58 $this->translator = $translator;
59 $this->events = $events;
60 $this->hooks = $hooks;
61 $this->datalist = $datalist;
70 public function run() {
77 if (!$this->mutex->lock(
'upgrade')) {
79 $result[
'reason'] = $this->translator->translate(
'upgrade:locked');
84 $this->events->unregisterHandler(
'log',
'systemlog',
'system_log_default_logger');
85 $this->events->unregisterHandler(
'all',
'all',
'system_log_listener');
90 if ($this->getUnprocessedUpgrades()) {
91 $this->processUpgrades();
94 $this->events->trigger(
'upgrade',
'system', null);
97 $this->mutex->unlock(
'upgrade');
113 $processed_upgrades = $this->getProcessedUpgrades();
115 $upgrade_files = $this->getUpgradeFiles($upgrade_path);
117 if ($upgrade_files ===
false) {
121 $upgrades = $this->getUnprocessedUpgrades($upgrade_files, $processed_upgrades);
127 $upgrade_version = $this->getUpgradeFileVersion($upgrade);
141 if (!@Includer::includeFile(
"$upgrade_path/$upgrade")) {
143 $this->logger->error(
"Could not include $upgrade_path/$upgrade");
147 $this->logger->error($e->getMessage());
150 if (!Includer::includeFile(
"$upgrade_path/$upgrade")) {
152 $this->logger->error(
"Could not include $upgrade_path/$upgrade");
160 $this->datalist->set(
'version', $upgrade_version);
164 $this->setProcessedUpgrade($upgrade);
181 $processed_upgrades = $this->getProcessedUpgrades();
182 $processed_upgrades[] = $upgrade;
183 $processed_upgrades = array_unique($processed_upgrades);
184 return $this->datalist->set(
'processed_upgrades', serialize($processed_upgrades));
193 $upgrades = $this->datalist->get(
'processed_upgrades');
195 return $unserialized;
206 preg_match(
'/^([0-9]{10})([\.a-z0-9-_]+)?\.(php)$/i',
$filename, $matches);
208 if (isset($matches[1])) {
209 return (
int) $matches[1];
222 if (!$upgrade_path) {
226 $handle = opendir($upgrade_path);
232 $upgrade_files = array();
234 while ($upgrade_file = readdir($handle)) {
236 if (is_dir($upgrade_path .
'$upgrade_file')) {
239 $upgrade_version = $this->getUpgradeFileVersion($upgrade_file);
240 if (!$upgrade_version) {
243 $upgrade_files[] = $upgrade_file;
246 sort($upgrade_files);
248 return $upgrade_files;
260 if ($upgrade_files === null) {
261 $upgrade_files = $this->getUpgradeFiles();
264 if ($processed_upgrades === null) {
265 $processed_upgrades = unserialize($this->datalist->get(
'processed_upgrades'));
266 if (!is_array($processed_upgrades)) {
267 $processed_upgrades = array();
271 $unprocessed = array_diff($upgrade_files, $processed_upgrades);
281 $dbversion = (int) $this->datalist->get(
'version');
283 if ($this->upgradeCode($dbversion)) {
287 $upgrade_details = new \stdClass;
288 $upgrade_details->from = $dbversion;
291 $this->events->trigger(
'upgrade',
'upgrade', $upgrade_details);
getUpgradeFiles($upgrade_path=null)
Returns a list of upgrade files relative to the $upgrade_path dir.
sanitise_filepath($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
$mutex
Unlocks the upgrade script.
setProcessedUpgrade($upgrade)
Saves a processed upgrade to a dataset.
run()
Run the upgrade process.
getUpgradeFileVersion($filename)
Returns the version of the upgrade filename.
Upgrade service for Elgg.
$upgrades
Lists pending upgrades.
getUnprocessedUpgrades($upgrade_files=null, $processed_upgrades=null)
Checks if any upgrades need to be run.
elgg system_message
Wrapper function for system_messages.
elgg_get_version($human_readable=false)
Get the current Elgg version information.
processUpgrades()
Upgrades Elgg Database and code.
elgg_get_engine_path()
/path/to/elgg/engine
__construct(\Elgg\i18n\Translator $translator,\Elgg\EventsService $events,\Elgg\PluginHooksService $hooks,\Elgg\Database\Datalist $datalist,\Elgg\Logger $logger,\Elgg\Database\Mutex $mutex)
Constructor.
elgg_flush_caches()
Flush all the registered caches.
getProcessedUpgrades()
Gets a list of processes upgrades.
upgradeCode($version, $quiet=false)
Run any php upgrade scripts which are required.