Merge pull request #5695 from annando/does-is-perform
[friendica.git/.git] / src / App.php
index 815b583..2a5fba8 100644 (file)
@@ -11,7 +11,6 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
-use Friendica\Database\DBM;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
@@ -141,6 +140,8 @@ class App
         * @brief App constructor.
         *
         * @param string $basepath Path to the app base folder
+        *
+        * @throws Exception if the Basepath is not usable
         */
        public function __construct($basepath)
        {
@@ -173,40 +174,7 @@ class App
                $this->callstack['rendering'] = [];
                $this->callstack['parser'] = [];
 
-               // The order of the following calls is important to ensure proper initialization
-               $this->loadConfigFiles();
-
-               $this->loadDatabase();
-
-               $this->determineMode();
-
-               $this->determineUrlPath();
-
-               Config::load();
-
-               if ($this->mode & self::MODE_DBAVAILABLE) {
-                       Core\Addon::loadHooks();
-
-                       $this->loadAddonConfig();
-               }
-
-               $this->loadDefaultTimezone();
-
-               $this->page = [
-                       'aside' => '',
-                       'bottom' => '',
-                       'content' => '',
-                       'end' => '',
-                       'footer' => '',
-                       'htmlhead' => '',
-                       'nav' => '',
-                       'page_title' => '',
-                       'right_aside' => '',
-                       'template' => '',
-                       'title' => ''
-               ];
-
-               $this->process_id = System::processID('log');
+               $this->reload();
 
                set_time_limit(0);
 
@@ -313,6 +281,47 @@ class App
                $this->register_template_engine('Friendica\Render\FriendicaSmartyEngine');
        }
 
+       /**
+        * Reloads the whole app instance
+        */
+       public function reload()
+       {
+               // The order of the following calls is important to ensure proper initialization
+               $this->loadConfigFiles();
+
+               $this->loadDatabase();
+
+               $this->determineMode();
+
+               $this->determineUrlPath();
+
+               Config::load();
+
+               if ($this->mode & self::MODE_DBAVAILABLE) {
+                       Core\Addon::loadHooks();
+
+                       $this->loadAddonConfig();
+               }
+
+               $this->loadDefaultTimezone();
+
+               $this->page = [
+                       'aside' => '',
+                       'bottom' => '',
+                       'content' => '',
+                       'end' => '',
+                       'footer' => '',
+                       'htmlhead' => '',
+                       'nav' => '',
+                       'page_title' => '',
+                       'right_aside' => '',
+                       'template' => '',
+                       'title' => ''
+               ];
+
+               $this->process_id = System::processID('log');
+       }
+
        /**
         * Load the configuration files
         *
@@ -1032,7 +1041,7 @@ class App
                        }
                }
 
-               $processlist = DBM::processlist();
+               $processlist = DBA::processlist();
                if ($processlist['list'] != '') {
                        logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);
 
@@ -1116,19 +1125,30 @@ class App
                return false;
        }
 
-       public function proc_run($args)
+       /**
+        * Executes a child process with 'proc_open'
+        *
+        * @param string $command The command to execute
+        * @param array  $args    Arguments to pass to the command ( [ 'key' => value, 'key2' => value2, ... ]
+        */
+       public function proc_run($command, $args)
        {
                if (!function_exists('proc_open')) {
                        return;
                }
 
-               array_unshift($args, $this->getConfigValue('config', 'php_path', 'php'));
+               $cmdline = $this->getConfigValue('config', 'php_path', 'php') . ' ' . escapeshellarg($command);
 
-               for ($x = 0; $x < count($args); $x ++) {
-                       $args[$x] = escapeshellarg($args[$x]);
-               }
+               foreach ($args as $key => $value) {
+                       if (!is_null($value) && is_bool($value) && !$value) {
+                               continue;
+                       }
 
-               $cmdline = implode(' ', $args);
+                       $cmdline .= ' --' . $key;
+                       if (!is_null($value) && !is_bool($value)) {
+                               $cmdline .= ' ' . $value;
+                       }
+               }
 
                if ($this->min_memory_reached()) {
                        return;
@@ -1297,11 +1317,11 @@ class App
                // Only arrays are serialized in database, so we have to unserialize sparingly
                $value = is_string($v) && preg_match("|^a:[0-9]+:{.*}$|s", $v) ? unserialize($v) : $v;
 
-               if (!isset($this->config[$uid])) {
+               if (!isset($this->config[$uid]) || !is_array($this->config[$uid])) {
                        $this->config[$uid] = [];
                }
 
-               if (!isset($this->config[$uid][$cat])) {
+               if (!isset($this->config[$uid][$cat]) || !is_array($this->config[$uid][$cat])) {
                        $this->config[$uid][$cat] = [];
                }
 
@@ -1384,21 +1404,17 @@ class App
                        // Allow folks to override user themes and always use their own on their own site.
                        // This works only if the user is on the same server
                        $user = DBA::selectFirst('user', ['theme'], ['uid' => $this->profile_uid]);
-                       if (DBM::is_result($user) && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
+                       if (DBA::isResult($user) && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
                                $page_theme = $user['theme'];
                        }
                }
 
-               if (!empty($_SESSION)) {
-                       $user_theme = defaults($_SESSION, 'theme', $system_theme);
-               } else {
-                       $user_theme = $system_theme;
-               }
+               $user_theme = Core\Session::get('theme', $system_theme);
 
                // Specific mobile theme override
-               if (($this->is_mobile || $this->is_tablet) && defaults($_SESSION, 'show-mobile', true)) {
+               if (($this->is_mobile || $this->is_tablet) && Core\Session::get('show-mobile', true)) {
                        $system_mobile_theme = Config::get('system', 'mobile-theme');
-                       $user_mobile_theme = defaults($_SESSION, 'mobile-theme', $system_mobile_theme);
+                       $user_mobile_theme = Core\Session::get('mobile-theme', $system_mobile_theme);
 
                        // --- means same mobile theme as desktop
                        if (!empty($user_mobile_theme) && $user_mobile_theme !== '---') {