54 private $system_messages;
81 $this->locator = $locator;
82 $this->translator = $translator;
83 $this->events = $events;
86 $this->system_messages = $system_messages;
87 $this->progress = $progress;
94 protected function up() {
95 return new Promise(
function ($resolve, $reject) {
96 Application::migrate();
98 if (!$this->events->triggerBefore(
'upgrade',
'system', null)) {
99 return $reject(
new \
RuntimeException($this->translator->translate(
'upgrade:terminated')));
103 if (!$this->mutex->lock(
'upgrade')) {
104 return $reject(
new \
RuntimeException($this->translator->translate(
'upgrade:locked')));
120 return new Promise(
function ($resolve, $reject) {
121 if (!$this->events->trigger(
'upgrade',
'system', null)) {
127 $this->mutex->unlock(
'upgrade');
129 $this->events->triggerAfter(
'upgrade',
'system', null);
150 $promises[] =
new Promise(
function ($resolve, $reject) use ($upgrade) {
152 $result = $this->executeUpgrade($upgrade,
false);
153 }
catch (\Throwable $ex) {
157 if (
$result->getFailureCount()) {
158 $msg =
elgg_echo(
'admin:upgrades:failed', [
159 $upgrade->getDisplayName(),
169 return all($promises);
181 set_time_limit(3600);
183 $deferred =
new Deferred();
185 $promise = $deferred->promise();
187 $resolve =
function (
$value) use ($deferred) {
188 $deferred->resolve(
$value);
191 $reject =
function (
$error) use ($deferred) {
192 $deferred->reject(
$error);
196 $upgrades = $this->getPendingUpgrades(
false);
200 function () use ($resolve, $reject,
$upgrades) {
204 function () use ($resolve, $reject) {
206 function (
$result) use ($resolve) {
234 if ($upgrade->isCompleted()) {
238 $batch = $upgrade->getBatch();
247 $pending = array_filter($pending,
function(\
ElggUpgrade $upgrade) {
266 function () use ($async) {
270 $order_by_completed_time->direction =
'DESC';
271 $order_by_completed_time->property =
'completed_time';
275 'subtype' =>
'elgg_upgrade',
276 'metadata_name' =>
'class',
277 'metadata_name_value_pairs' => [
278 'name' =>
'is_completed',
281 'order_by' => $order_by_completed_time,
287 $batch = $upgrade->getBatch();
296 $completed = array_filter($completed,
function(\
ElggUpgrade $upgrade) {
320 function () use ($upgrade, $max_duration) {
321 return $this->events->triggerResultsSequence(
'upgrade:execute',
'system', [
'object' => $upgrade], null,
function() use ($upgrade, $max_duration) {
331 $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.
getCompletedUpgrades($async=true)
Get completed (async) upgrades ordered by recently completed first.
$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.
Provides database mutex that can be used to prevent race conditions between two processes that affect...
Extends QueryBuilder with clauses necesary 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
executeUpgrade(\ElggUpgrade $upgrade, $max_duration=null)
Call the upgrade's run() for a specified period of time, or until it completes.
if(empty($guid)) $upgrade
getPendingUpgrades($async=true)
Get pending async upgrades.
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.
__construct(Locator $locator, Translator $translator, EventsService $events, Config $config, Mutex $mutex, SystemMessagesService $system_messages, Progress $progress)
Constructor.
Result of a single BatchUpgrade run.
down()
Finish an upgrade process.
up()
Start an upgrade process.
getLogger()
Returns logger.
run($upgrades=null)
Run the upgrade process.
elgg_clear_caches()
Clear all the registered caches.
Upgrade loop Executes upgrade batches for a given duration of time.