55 private $system_messages;
84 $this->locator = $locator;
85 $this->translator = $translator;
86 $this->events = $events;
88 $this->logger = $logger;
90 $this->system_messages = $system_messages;
91 $this->progress = $progress;
98 protected function up() {
99 return new Promise(
function ($resolve, $reject) {
100 Application::migrate();
102 if (!$this->events->triggerBefore(
'upgrade',
'system', null)) {
103 return $reject(
new RuntimeException($this->translator->translate(
'upgrade:terminated')));
107 if (!$this->mutex->lock(
'upgrade')) {
108 return $reject(
new RuntimeException($this->translator->translate(
'upgrade:locked')));
124 return new Promise(
function ($resolve, $reject) {
125 if (!$this->events->trigger(
'upgrade',
'system', null)) {
131 $this->mutex->unlock(
'upgrade');
133 $this->events->triggerAfter(
'upgrade',
'system', null);
146 return new Promise(
function ($resolve, $reject) {
147 if ($this->getUnprocessedUpgrades()) {
148 $this->processUpgrades();
169 $promises[] =
new Promise(
function ($resolve, $reject) use (
$upgrade) {
176 if (
$result->getFailureCount()) {
177 $msg =
elgg_echo(
'admin:upgrades:failed', [
188 return all($promises);
201 set_time_limit(3600);
203 $deferred =
new Deferred();
205 $promise = $deferred->promise();
207 $resolve =
function (
$value) use ($deferred) {
208 $deferred->resolve(
$value);
211 $reject =
function (
$error) use ($deferred) {
212 $deferred->reject(
$error);
216 $upgrades = $this->getPendingUpgrades(
false);
220 function () use ($resolve, $reject,
$upgrades) {
222 $this->runLegacyUpgrades(),
225 function () use ($resolve, $reject) {
227 function (
$result) use ($resolve) {
255 $processed_upgrades = $this->getProcessedUpgrades();
257 $upgrade_files = $this->getUpgradeFiles($upgrade_path);
259 if ($upgrade_files ===
false) {
263 $upgrades = $this->getUnprocessedUpgrades($upgrade_files, $processed_upgrades);
269 $upgrade_version = $this->getUpgradeFileVersion($upgrade);
283 if (!@Includer::includeFile(
"$upgrade_path/$upgrade")) {
285 $this->logger->error(
"Could not include $upgrade_path/$upgrade");
289 $this->logger->error($e);
292 if (!Includer::includeFile(
"$upgrade_path/$upgrade")) {
294 $this->logger->error(
"Could not include $upgrade_path/$upgrade");
302 $this->config->save(
'version', $upgrade_version);
306 $this->setProcessedUpgrade($upgrade);
326 $processed_upgrades = $this->getProcessedUpgrades();
328 $processed_upgrades = array_unique($processed_upgrades);
330 return $this->config->save(
'processed_upgrades', $processed_upgrades);
341 return $this->config->processed_upgrades;
355 preg_match(
'/^([0-9]{10})([\.a-z0-9-_]+)?\.(php)$/i',
$filename, $matches);
357 if (isset($matches[1])) {
358 return (
int) $matches[1];
374 if (!$upgrade_path) {
379 if (!is_dir($upgrade_path)) {
383 $handle = opendir($upgrade_path);
390 while (($upgrade_file = readdir($handle)) !==
false) {
392 if (!is_file($upgrade_path . $upgrade_file)) {
395 $upgrade_version = $this->getUpgradeFileVersion($upgrade_file);
396 if (!$upgrade_version) {
399 $upgrade_files[] = $upgrade_file;
402 sort($upgrade_files);
404 return $upgrade_files;
418 if ($upgrade_files === null) {
419 $upgrade_files = $this->getUpgradeFiles();
422 if (empty($upgrade_files)) {
426 if ($processed_upgrades === null) {
427 $processed_upgrades = $this->config->processed_upgrades;
428 if (!is_array($processed_upgrades)) {
429 $processed_upgrades = [];
433 $unprocessed = array_diff($upgrade_files, $processed_upgrades);
446 $dbversion = (int) $this->config->version;
448 if ($this->upgradeCode($dbversion)) {
468 if ($upgrade->isCompleted()) {
472 $batch = $upgrade->getBatch();
481 $pending = array_filter($pending,
function(
ElggUpgrade $upgrade) {
501 'subtype' =>
'elgg_upgrade',
502 'private_setting_name' =>
'class',
503 'private_setting_name_value_pairs' => [
504 'name' =>
'is_completed',
512 $batch = $upgrade->getBatch();
521 $completed = array_filter($completed,
function(
ElggUpgrade $upgrade) {
544 function () use ($upgrade, $max_duration) {
545 return $this->events->triggerSequence(
'upgrade:execute',
'system', $upgrade,
function() use ($upgrade, $max_duration) {
555 $loop->loop($max_duration);
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
runLegacyUpgrades()
Run legacy upgrade scripts.
getUpgradeFiles($upgrade_path=null)
Returns a list of upgrade files relative to the $upgrade_path dir.
Locates and registers both core and plugin upgrades.
getCompletedUpgrades($async=true)
Get completed (async) upgrades.
$mutex
Unlocks the upgrade script.
if(!$enabled) if(PHP_SAPI!== 'cli')
Interates through each element of an array and calls callback a function.
setProcessedUpgrade($upgrade)
Saves a processed upgrade to a dataset.
trait Loggable
Enables adding a logger.
getUpgradeFileVersion($filename)
Returns the version of the upgrade filename.
_elgg_disable_caches()
Disable all caches.
isAsynchronous()
Check if the upgrade should be run asynchronously.
Upgrade service for Elgg.
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
__construct(Locator $locator, Translator $translator, EventsService $events, Config $config, Logger $logger, Mutex $mutex, SystemMessagesService $system_messages, Progress $progress)
Constructor.
$config
Advanced site settings, debugging section.
$upgrades
Lists pending upgrades.
const ELGG_IGNORE_ACCESS
elgg_call() flags
getPendingUpgrades($async=true)
Get pending async upgrades.
getUnprocessedUpgrades($upgrade_files=null, $processed_upgrades=null)
Checks if any upgrades need to be run.
const ELGG_SHOW_DISABLED_ENTITIES
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
runUpgrades($upgrades)
Run system and async upgrades.
_elgg_clear_caches()
Clear all caches.
Result of a single BatchUpgrade run.
down()
Finish an upgrade process.
up()
Start an upgrade process.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
executeUpgrade(ElggUpgrade $upgrade, $max_duration=null)
Call the upgrade's run() for a specified period of time, or until it completes.
processUpgrades()
Upgrades Elgg Database and code.
static sanitize($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
elgg_get_engine_path()
/path/to/elgg/engine with no trailing slash.
run($upgrades=null)
Run the upgrade process.
elgg_flush_caches()
Flush all the registered caches.
getProcessedUpgrades()
Gets a list of processes upgrades.
Upgrade loop Executes upgrade batches for a given duration of time.
upgradeCode($version, $quiet=false)
Run any php upgrade scripts which are required.