+ /**
+ * @brief Synchronise addons:
+ *
+ * system.addon contains a comma-separated list of names
+ * of addons which are used on this system.
+ * Go through the database list of already installed addons, and if we have
+ * an entry, but it isn't in the config list, call the uninstall procedure
+ * and mark it uninstalled in the database (for now we'll remove it).
+ * Then go through the config list and if we have a addon that isn't installed,
+ * call the install procedure and add it to the database.
+ *
+ */
+ public static function check()
+ {
+ $a = self::getApp();
+
+ $r = DBA::select('addon', [], ['installed' => 1]);
+ if (DBA::isResult($r)) {
+ $installed = DBA::toArray($r);
+ } else {
+ $installed = [];
+ }
+
+ $addons = Config::get('system', 'addon');
+ $addons_arr = [];
+
+ if ($addons) {
+ $addons_arr = explode(',', str_replace(' ', '', $addons));
+ }
+
+ $a->addons = $addons_arr;
+
+ $installed_arr = [];
+
+ if (count($installed)) {
+ foreach ($installed as $i) {
+ if (!in_array($i['name'], $addons_arr)) {
+ self::uninstall($i['name']);
+ } else {
+ $installed_arr[] = $i['name'];
+ }
+ }
+ }
+
+ if (count($addons_arr)) {
+ foreach ($addons_arr as $p) {
+ if (!in_array($p, $installed_arr)) {
+ self::install($p);
+ }
+ }
+ }
+
+ self::loadHooks();
+
+ return;
+ }
+