/** * Creates new ElggUpgrade instance from plugin's static config * * @param \ElggPlugin $plugin Plugin * @return \ElggUpgrade[] */ public function getUpgrades(\ElggPlugin $plugin) { $upgrades = []; $batches = $plugin->getStaticConfig('upgrades'); if (empty($batches)) { // No upgrades available for this plugin return $upgrades; } $plugin_id = $plugin->getID(); foreach ($batches as $class) { $batch = $this->getBatch($class); if (!$batch) { continue; } $version = $batch::VERSION; $upgrade_id = "{$plugin_id}:{$version}"; // Database holds the information of which upgrades have been processed if ($this->upgradeExists($upgrade_id)) { $this->logger->info("Upgrade {$upgrade_id} has already been processed"); continue; } // Create a new ElggUpgrade to represent the upgrade in the database $object = new ElggUpgrade(); $object->setId($upgrade_id); $object->setClass($class); $object->title = "{$plugin_id}:upgrade:{$version}:title"; $object->description = "{$plugin_id}:upgrade:{$version}:description"; $object->offset = 0; try { $object->save(); $upgrades[] = $object; } catch (\UnexpectedValueException $ex) { $this->logger->error($ex->getMessage()); } } return $upgrades; }