/** * Check plugin needs migration. * * @param $pluginName * @return bool */ public function needMigrate($pluginName) { $return = false; if (Plugin::loaded($pluginName)) { $migrateManager = UnionManager::getInstance($pluginName); $migrations = $migrateManager->getMigrations(); foreach ($migrations as $migration) { $isMigrated = $migrateManager->isMigrated($migration->getVersion()); if (!$isMigrated) { $return = true; break; } } } return $return; }
/** * Migrate plugin action. * * @param null $alias * @return void|\Cake\Network\Response */ public function migrate($alias = null) { $plugin = $this->Plugins->findByAlias($alias)->first(); if (CakePlugin::loaded($plugin->getName())) { $pluginDomainName = sprintf('<strong>%s</strong>', __d($plugin->alias, $plugin->name)); $migrations = $plugin->getMigrations(); if (empty($migrations)) { $this->Flash->error(__d('extensions', 'Not found migration for «{0}»', $pluginDomainName)); return $this->redirect(['action' => 'index']); } $result = UnionManager::getInstance($plugin->getName())->migrate(); if (!empty($result)) { $this->Flash->success($this->Union->arrayFlashMessage($result)); return $this->redirect(['action' => 'index']); } $this->Flash->success(__d('extensions', 'Not found migrations for plugin «{0}»', $pluginDomainName)); return $this->redirect(['action' => 'index']); } else { throw new MissingPluginException(['plugin' => $plugin->getName()]); } }