53 protected function up(): Promise {
54 return new Promise(
function ($resolve, $reject) {
55 Application::migrate();
57 if (!$this->events->triggerBefore(
'upgrade',
'system', null)) {
58 return $reject(
new \
RuntimeException($this->translator->translate(
'upgrade:terminated')));
62 if (!$this->mutex->lock(
'upgrade')) {
63 return $reject(
new \
RuntimeException($this->translator->translate(
'upgrade:locked')));
79 protected function down(): Promise {
80 return new Promise(
function ($resolve, $reject) {
81 if (!$this->events->trigger(
'upgrade',
'system', null)) {
87 $this->mutex->unlock(
'upgrade');
89 $this->events->triggerAfter(
'upgrade',
'system', null);
110 $promises[] =
new Promise(
function ($resolve, $reject) use ($upgrade) {
112 $result = $this->executeUpgrade($upgrade, 0);
113 }
catch (\Throwable $ex) {
117 if (
$result->getFailureCount()) {
118 $msg =
elgg_echo(
'admin:upgrades:failed', [
119 $upgrade->getDisplayName(),
129 return all($promises);
141 set_time_limit(3600);
143 $deferred =
new Deferred();
145 $promise = $deferred->promise();
147 $resolve =
function (
$value) use ($deferred) {
148 $deferred->resolve(
$value);
151 $reject =
function (
$error) use ($deferred) {
152 $deferred->reject(
$error);
156 $upgrades = $this->getPendingUpgrades(
false);
160 function () use ($resolve, $reject,
$upgrades) {
164 function () use ($resolve, $reject) {
166 function (
$result) use ($resolve) {
194 if ($upgrade->isCompleted()) {
198 $batch = $upgrade->getBatch();
207 $pending = array_filter($pending,
function(\
ElggUpgrade $upgrade) {
226 function () use ($async) {
230 $order_by_completed_time->direction =
'DESC';
231 $order_by_completed_time->property =
'completed_time';
235 'subtype' =>
'elgg_upgrade',
236 'metadata_name' =>
'class',
237 'metadata_name_value_pairs' => [
238 'name' =>
'is_completed',
241 'order_by' => $order_by_completed_time,
247 $batch = $upgrade->getBatch();
256 $completed = array_filter($completed,
function(\
ElggUpgrade $upgrade) {
280 function () use ($upgrade, $max_duration) {
281 return $this->events->triggerResultsSequence(
'upgrade:execute',
'system', [
'object' => $upgrade], null,
function() use ($upgrade, $max_duration) {
291 $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.
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.
executeUpgrade(\ElggUpgrade $upgrade, int $max_duration=null)
Call the upgrade's run() for a specified period of time, or until it completes.
Upgrade loop Executes upgrade batches for a given duration of time.