Elgg  Version 4.3
DeleteDiagnosticsPlugin.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Upgrades;
4 
7 
12 
16  public function getVersion(): int {
17  return 2020102301;
18  }
19 
23  public function needsIncrementOffset(): bool {
24  return false;
25  }
26 
30  public function shouldBeSkipped(): bool {
31  return empty($this->countItems());
32  }
33 
37  public function countItems(): int {
38  $plugin = elgg_get_plugin_from_id('diagnostics');
39  if ($plugin instanceof \ElggPlugin) {
40  return 1;
41  }
42 
43  return 0;
44  }
45 
49  public function run(Result $result, $offset): Result {
50  $plugin = elgg_get_plugin_from_id('diagnostics');
51  if (!$plugin instanceof \ElggPlugin) {
52  $result->addSuccesses(1);
53  return $result;
54  }
55 
56  _elgg_services()->logger->disable();
57 
58  if ($plugin->delete()) {
59  $result->addSuccesses(1);
60  } else {
61  $result->addFailures(1);
62  }
63 
64  _elgg_services()->logger->enable();
65 
66  return $result;
67  }
68 }
$plugin
needsIncrementOffset()
Should the run() method receive an offset representing all processed items?If true, run() will receive as $offset the number of items already processed. This is useful if you are only modifying data, and need to use the $offset in a function like elgg_get_entities*() to know how many to skip over.If false, run() will receive as $offset the total number of failures. This should be used if your process deletes or moves data out of the way of the process. E.g. if you delete 50 objects on each run(), you may still use the $offset to skip objects that already failed once.bool
elgg_get_plugin_from_id(string $plugin_id)
Elgg plugins library Contains functions for managing plugins.
Definition: plugins.php:15
addFailures(int $num=1)
Increment failure count.
Definition: Result.php:53
if(!$count) $offset
Definition: pagination.php:26
addSuccesses(int $num=1)
Set an item (or items) as successfully upgraded.
Definition: Result.php:73
countItems()
The total number of items to process during the upgrade.If unknown, Batch::UNKNOWN_COUNT should be re...
Result of a single BatchUpgrade run.
Definition: Result.php:10
shouldBeSkipped()
Should this upgrade be skipped?If true, the upgrade will not be performed and cannot be accessed late...
Remove the diagnostics plugin entity.
getVersion()
Version of the upgrade.This tells the date when the upgrade was added. It consists of eight digits an...
run(Result $result, $offset)
Runs upgrade on a single batch of items.If countItems() returns Batch::UNKNOWN_COUNT, this method must call $result->markCompleted() when the upgrade is complete.Result of the batch (this must be returned) Number to skip when processingResult
System upgrades are executed synchronously at system upgrade.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638