#!/bin/bash

COMPOSER="composer --working-dir=$GITROOT"

#
# Upgrade process:
#

# 1. Clear composer cache and update all packages
${COMPOSER} clear-cache && ${COMPOSER} update

# 2. since we might have upgraded the platform package, re-install it
cividesk-platform-install

# 3. now we can upgrade the CMS and CiviCRM
# TODO: CMS upgrade commands based on env variables
cv updb # will handle CiviCRM core and extensions

# 4. And finally, reconfigure everything as intended
cividesk-platform-configure

# 5. Trigger CiviCRM pingback after platform update/rebuild
cv ev '$versionCheck = new CRM_Utils_VersionCheck(); $versionCheck->flushCache(); $versionCheck->fetch();'