54 protected function up(): Promise {
55 return new Promise(
function ($resolve, $reject) {
56 Application::migrate();
58 if (!$this->events->triggerBefore(
'upgrade',
'system', null)) {
59 return $reject(
new \
RuntimeException($this->translator->translate(
'upgrade:terminated')));
63 if (!$this->mutex->lock(
'upgrade')) {
64 return $reject(
new \
RuntimeException($this->translator->translate(
'upgrade:locked')));
71 return $resolve(
true);
80 protected function down(): Promise {
81 return new Promise(
function ($resolve, $reject) {
82 if (!$this->events->trigger(
'upgrade',
'system', null)) {
83 return $reject(
false);
88 $this->mutex->unlock(
'upgrade');
90 $this->events->triggerAfter(
'upgrade',
'system', null);
92 return $resolve(
true);
111 $promises[] =
new Promise(
function ($resolve, $reject) use ($upgrade) {
113 $result = $this->executeUpgrade($upgrade, 0);
114 }
catch (\Throwable $ex) {
118 if (
$result->getFailureCount()) {
119 $msg =
elgg_echo(
'admin:upgrades:failed', [
120 $upgrade->getDisplayName(),
130 return all($promises);
142 set_time_limit(3600);
144 $deferred =
new Deferred();
146 $promise = $deferred->promise();
148 $resolve =
function (
$value) use ($deferred) {
149 $deferred->resolve(
$value);
152 $reject =
function (
$error) use ($deferred) {
153 $deferred->reject(
$error);
157 $upgrades = $this->getPendingUpgrades(
false);
161 function () use ($resolve, $reject,
$upgrades) {
165 function () use ($resolve, $reject) {
167 function (
$result) use ($resolve) {
195 if ($upgrade->isCompleted()) {
199 $batch = $upgrade->getBatch();
208 $pending = array_filter($pending,
function(\
ElggUpgrade $upgrade) {
227 function () use ($async) {
231 $order_by_completed_time->direction =
'DESC';
232 $order_by_completed_time->property =
'completed_time';
236 'subtype' =>
'elgg_upgrade',
237 'metadata_name' =>
'class',
238 'metadata_name_value_pairs' => [
239 'name' =>
'is_completed',
242 'order_by' => $order_by_completed_time,
248 $batch = $upgrade->getBatch();
257 $completed = array_filter($completed,
function(\
ElggUpgrade $upgrade) {
281 function () use ($upgrade, $max_duration) {
282 return $this->events->triggerResultsSequence(
'upgrade:execute',
'system', [
'object' => $upgrade], null,
function() use ($upgrade, $max_duration) {
292 $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...
Exception thrown if an error which can only be found on runtime occurs.
Locates and registers both core and plugin upgrades.
$mutex
Unlocks the upgrade script.
static disable()
Disables the caches in the system.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
getPendingUpgrades(bool $async=true)
Get pending async upgrades.
Provides database mutex that can be used to prevent race conditions between two processes that affect...
Extends QueryBuilder with clauses necessary to sort entity lists by entity properties.
isAsynchronous()
Check if the upgrade should be run asynchronously.
Upgrade service for Elgg.
elgg_invalidate_caches()
Invalidate all the registered caches.
$config
Advanced site settings, debugging section.
$upgrades
Lists pending upgrades.
trait Loggable
Enables adding a logger.
const ELGG_IGNORE_ACCESS
elgg_call() flags
if(empty($guid)) $upgrade
const ELGG_SHOW_DISABLED_ENTITIES
Represents an upgrade that runs outside of the upgrade.php script.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
runUpgrades($upgrades)
Run system and async upgrades.
Result of a single BatchUpgrade run.
const ELGG_SHOW_DELETED_ENTITIES
down()
Finish an upgrade process.
up()
Start an upgrade process.
getLogger()
Returns logger.
__construct(protected Locator $locator, protected Translator $translator, protected EventsService $events, protected Config $config, protected Mutex $mutex, protected SystemMessagesService $system_messages, protected Progress $progress)
Constructor.
executeUpgrade(\ElggUpgrade $upgrade,?int $max_duration=null)
Call the upgrade's run() for a specified period of time, or until it completes.
run($upgrades=null)
Run the upgrade process.
getCompletedUpgrades(bool $async=true)
Get completed (async) upgrades ordered by recently completed first.
elgg_clear_caches()
Clear all the registered caches.
Upgrade loop Executes upgrade batches for a given duration of time.