set('content_version', $timestamp); }); })->once(); before('magento:deploy:assets', 'magento:sync:content_version'); desc('Enables maintenance mode'); task('magento:maintenance:enable', function () { run("if [ -d $(echo {{current_path}}) ]; then {{bin/php}} {{current_path}}/bin/magento maintenance:enable; fi"); }); desc('Disables maintenance mode'); task('magento:maintenance:disable', function () { run("if [ -d $(echo {{current_path}}) ]; then {{bin/php}} {{current_path}}/bin/magento maintenance:disable; fi"); }); desc('Config Import'); task('magento:config:import', function () { $configImportNeeded = false; if(version_compare(get('magento_version'), '2.2.0', '<')) { //app:config:import command does not exist in 2.0.x and 2.1.x branches $configImportNeeded = false; } elseif(version_compare(get('magento_version'), '2.2.4', '<')) { //app:config:status command does not exist until 2.2.4, so proceed with config:import in every deploy $configImportNeeded = true; } else { try { run('{{bin/php}} {{release_or_current_path}}/bin/magento app:config:status'); } catch (RunException $e) { if ($e->getExitCode() == CONFIG_IMPORT_NEEDED_EXIT_CODE) { $configImportNeeded = true; } else { throw $e; } } } if ($configImportNeeded) { if (get('enable_zerodowntime') && !get('maintenance_mode_status_active')) { invoke('magento:maintenance:enable'); } run('{{bin/php}} {{release_or_current_path}}/bin/magento app:config:import --no-interaction'); if (get('enable_zerodowntime') && !get('maintenance_mode_status_active')) { invoke('magento:maintenance:disable'); } } }); desc('Upgrades magento database'); task('magento:upgrade:db', function () { $databaseUpgradeNeeded = false; try { run('{{bin/php}} {{release_or_current_path}}/bin/magento setup:db:status'); } catch (RunException $e) { if ($e->getExitCode() == DB_UPDATE_NEEDED_EXIT_CODE) { $databaseUpgradeNeeded = true; } else { throw $e; } } if ($databaseUpgradeNeeded) { if (get('enable_zerodowntime') && !get('maintenance_mode_status_active')) { invoke('magento:maintenance:enable'); } run("{{bin/php}} {{release_or_current_path}}/bin/magento setup:upgrade --keep-generated --no-interaction"); if (get('enable_zerodowntime') && !get('maintenance_mode_status_active')) { invoke('magento:maintenance:disable'); } } }); desc('Flushes Magento Cache'); task('magento:cache:flush', function () { run("{{bin/php}} {{release_or_current_path}}/bin/magento cache:flush"); }); desc('Magento2 deployment operations'); task('deploy:magento', [ 'magento:build', 'magento:config:import', 'magento:upgrade:db', 'magento:cache:flush', ]); desc('Magento2 build operations'); task('magento:build', [ 'magento:compile', 'magento:deploy:assets', ]); desc('Deploys your project'); task('deploy', [ 'deploy:prepare', 'deploy:vendors', 'deploy:clear_paths', 'deploy:magento', 'deploy:publish', ]); after('deploy:failed', 'magento:maintenance:disable');