Elgg  Version 3.0
ActivateNewPlugins.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Upgrades;
4 
7 
12 
13  protected $plugins = [
14  'activity',
15  'friends',
16  'friends_collections',
17  'system_log',
18  ];
19 
26  protected function getPluginIDs() {
27  $result = [];
28 
29  $plugins_path = elgg_get_plugins_path();
30  foreach ($this->plugins as $plugin_id) {
31  if (!is_dir($plugins_path . $plugin_id)) {
32  // plugin is not installed
33  // maybe using MIT version or otherwise modified version of Elgg
34  continue;
35  }
36 
37  // plugin exists
38  $result[] = $plugin_id;
39  }
40 
41  return $result;
42  }
43 
47  public function getVersion() {
48  return 2018041800;
49  }
50 
54  public function shouldBeSkipped() {
55  return empty($this->getPluginIDs());
56  }
57 
61  public function needsIncrementOffset() {
62  return false;
63  }
64 
68  public function countItems() {
69  return count($this->getPluginIDs());
70  }
71 
75  public function run(Result $result, $offset) {
77 
78  foreach ($this->getPluginIDs() as $id) {
80 
81  if (!$plugin) {
82  $result->addFailures(1);
83  $result->addError(elgg_echo('PluginException:InvalidPlugin', [
84  $id,
85  ]));
86  continue;
87  }
88 
89  if ($plugin->isActive()) {
90  $result->addSuccesses(1);
91  continue;
92  }
93 
94  try {
95  if ($plugin->activate()) {
96  $result->addSuccesses(1);
97  } else {
98  $result->addError($plugin->getID() . ': ' . $plugin->getError());
99  $result->addFailures(1);
100  }
101  } catch (\Exception $ex) {
102  $result->addError($ex->getMessage());
103  $result->addFailures(1);
104  }
105  }
106  }
107 }
Activate plugins added in Elgg 3.0.
$plugin
if(!$count) $offset
Definition: pagination.php:26
getPluginIDs()
Not all plugins which should be active have to be installed, for example in the MIT version of Elgg...
shouldBeSkipped()
{Should this upgrade be skipped?If true, the upgrade will not be performed and cannot be accessed lat...
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
addSuccesses($num=1)
Set an item (or items) as successfully upgraded.
Definition: Result.php:68
getVersion()
{Version of the upgrade.This tells the date when the upgrade was added. It consists of eight digits a...
countItems()
{The total number of items to process during the upgrade.If unknown, Batch::UNKNOWN_COUNT should be r...
$id
River item delete action.
Definition: delete.php:6
addFailures($num=1)
Increment failure count.
Definition: Result.php:49
$plugin_id
Definition: save.php:15
addError($message)
Add new error message to the batch.
Definition: Result.php:24
Result of a single BatchUpgrade run.
Definition: Result.php:8
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}
System upgrades are executed synchronously at system upgrade.
elgg_get_plugins_path()
Get the plugin path for this installation, ending with slash.
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}
_elgg_generate_plugin_entities()
Elgg plugins library Contains functions for managing plugins.
Definition: plugins.php:17
elgg_get_plugin_from_id($plugin_id)
Returns an object with the path $path.
Definition: plugins.php:28