public function testQueueCompleteEventHandler() { $files = ['task401', 'task402']; $testChain = new ReportingChain(); foreach ($files as $f) { if (file_exists("/tmp/{$f}")) { unlink("/tmp/{$f}"); } $testTask = new ReportingTask(); $testTask->cliCommand('touch', ["/tmp/{$f}"]); $testChain->addTask($testTask); } $firstTaskId = $testChain->registerChain(); DeferredHelper::runImmediateTask($firstTaskId); sleep(2); $this->assertTrue(file_exists('/tmp/task401')); /** @var DeferredQueue $queue */ $queue = DeferredQueue::findOne(['id' => $firstTaskId]); $process = new Process('pwd > /dev/null'); $process->run(); $queue->setProcess($process); $event = new DeferredQueueCompleteEvent($queue); QueueCompleteEventHandler::handleEvent($event); sleep(2); $this->assertTrue(file_exists('/tmp/task402')); }
/** * Adds uninstall task into ReportingChain * * @param $extension * @param ReportingChain $chain */ private static function uninstall($extension, ReportingChain $chain) { $module = ExtensionsManager::module(); if (true === $module->extensionIsCore($extension['composer_name'])) { $dummyTask = ExtensionDataHelper::buildTask([realpath(Yii::getAlias('@app') . '/yii'), 'extension/dummy', '--no-interaction', '-o', 'You are unable to uninstall core extensions!'], ExtensionsManager::EXTENSION_DUMMY_DEFERRED_GROUP); $chain->addTask($dummyTask); } else { self::deactivate($extension, $chain); $uninstallTask = ExtensionDataHelper::buildTask([$module->composerPath, 'remove', $extension['composer_name'], "--working-dir={$module->getLocalExtensionsPath()}", $module->verbose == 1 ? '-vvv' : ''], ExtensionsManager::COMPOSER_UNINSTALL_DEFERRED_GROUP); $chain->addTask($uninstallTask); } }
/** * Prepares migration command * * @param array $ext * @param ReportingChain $chain * @param string $way * @param $group */ public static function prepareMigrationTask(array $ext, ReportingChain $chain, $way = ExtensionsManager::MIGRATE_TYPE_UP, $group) { if ($ext['composer_type'] == Extension::TYPE_DOTPLANT) { $extData = ComposerInstalledSet::get()->getInstalled($ext['composer_name']); $packageMigrations = ExtensionDataHelper::getInstalledExtraData($extData, 'migrationPath', true); $packagePath = '@vendor' . '/' . $ext['composer_name'] . '/'; foreach ($packageMigrations as $migrationPath) { $migrateTask = self::buildTask([realpath(Yii::getAlias('@app') . '/yii'), 'migrate/' . $way, '--migrationPath=' . $packagePath . $migrationPath, '--color=0', '--interactive=0', '--disableLookup=true', ExtensionsManager::MIGRATE_TYPE_DOWN == $way ? 68888 : ''], $group); $chain->addTask($migrateTask); } } }