]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
Merge pull request #3269 from annando/1703-nodeinfo
[friendica.git] / boot.php
index b8e92670708836c6d5b9c376185120031e914161..6f036d846e90887faa62cc21baf2256bb7224cfc 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -32,15 +32,14 @@ require_once('include/cache.php');
 require_once('library/Mobile_Detect/Mobile_Detect.php');
 require_once('include/features.php');
 require_once('include/identity.php');
-require_once('include/pidfile.php');
 require_once('update.php');
 require_once('include/dbstructure.php');
 
 define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Asparagus');
-define ( 'FRIENDICA_VERSION',      '3.5.1-dev' );
+define ( 'FRIENDICA_VERSION',      '3.5.2-dev' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1214      );
+define ( 'DB_UPDATE_VERSION',      1216      );
 
 /**
  * @brief Constant with a HTML line break.
@@ -442,10 +441,17 @@ define('SR_SCOPE_ALL',  'all');
 define('SR_SCOPE_TAGS', 'tags');
 /* @}*/
 
+/**
+ * Lowest possible date time value
+ */
+
+define ('NULL_DATE', '0001-01-01 00:00:00');
+
+
 // Normally this constant is defined - but not if "pcntl" isn't installed
-if (!defined("SIGTERM"))
+if (!defined("SIGTERM")) {
        define("SIGTERM", 15);
-
+}
 /**
  *
  * Reverse the effect of magic_quotes_gpc if it is enabled.
@@ -1346,60 +1352,25 @@ class App {
                return false;
        }
 
-       /**
-        * @brief Checks if the process is already running
-        *
-        * @param string $taskname The name of the task that will be used for the name of the lockfile
-        * @param string $task The path and name of the php script
-        * @param int $timeout The timeout after which a task should be killed
-        *
-        * @return bool Is the process running?
-        */
-       function is_already_running($taskname, $task = "", $timeout = 540) {
-
-               $lockpath = get_lockpath();
-               if ($lockpath != '') {
-                       $pidfile = new pidfile($lockpath, $taskname);
-                       if ($pidfile->is_already_running()) {
-                               logger("Already running");
-                               if ($pidfile->running_time() > $timeout) {
-                                       $pidfile->kill();
-                                       logger("killed stale process");
-                                       // Calling a new instance
-                                       if ($task != "")
-                                               proc_run(PRIORITY_MEDIUM, $task);
-                               }
-                               return true;
-                       }
-               }
-               return false;
-       }
-
        function proc_run($args) {
 
                if (!function_exists("proc_open")) {
                        return;
                }
 
-               // Add the php path if it is a php call
-               if (count($args) && ($args[0] === 'php' OR !is_string($args[0]))) {
-
-                       // If the last worker fork was less than 10 seconds before then don't fork another one.
-                       // This should prevent the forking of masses of workers.
-                       if (get_config("system", "worker")) {
-                               $cachekey = "app:proc_run:started";
-                               $result = Cache::get($cachekey);
-                               if (!is_null($result)) {
-                                       if ((time() - $result) < 10) {
-                                               return;
-                                       }
-                               }
-                               // Set the timestamp of the last proc_run
-                               Cache::set($cachekey, time(), CACHE_MINUTE);
+               // If the last worker fork was less than 10 seconds before then don't fork another one.
+               // This should prevent the forking of masses of workers.
+               $cachekey = "app:proc_run:started";
+               $result = Cache::get($cachekey);
+               if (!is_null($result)) {
+                       if ((time() - $result) < 10) {
+                               return;
                        }
-
-                       $args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php');
                }
+               // Set the timestamp of the last proc_run
+               Cache::set($cachekey, time(), CACHE_MINUTE);
+
+               array_unshift($args, ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'));
 
                // add baseurl to args. cli scripts can't construct it
                $args[] = $this->get_baseurl();
@@ -1889,11 +1860,35 @@ function goaway($s) {
  * @return int|bool user id or false
  */
 function local_user() {
-       if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
+       if (x($_SESSION, 'authenticated') && x($_SESSION, 'uid')) {
                return intval($_SESSION['uid']);
+       }
        return false;
 }
 
+/**
+ * @brief Returns the public contact id of logged in user or false.
+ *
+ * @return int|bool public contact id or false
+ */
+function public_contact() {
+       static $public_contact_id = false;
+
+       if (!$public_contact_id && x($_SESSION, 'authenticated')) {
+               if (x($_SESSION, 'my_address')) {
+                       // Local user
+                       $public_contact_id = intval(get_contact($_SESSION['my_address'], 0));
+               } else if (x($_SESSION, 'visitor_home')) {
+                       // Remote user
+                       $public_contact_id = intval(get_contact($_SESSION['visitor_home'], 0));
+               }
+       } else if (!x($_SESSION, 'authenticated')) {
+               $public_contact_id = false;
+       }
+
+       return $public_contact_id;
+}
+
 /**
  * @brief Returns contact id of authenticated site visitor or false
  *
@@ -1952,10 +1947,9 @@ function get_max_import_size() {
  * @brief Wrap calls to proc_close(proc_open()) and call hook
  *     so plugins can take part in process :)
  *
- * @param (string|integer|array) $cmd program to run, priority or parameter array
+ * @param (integer|array) priority or parameter array, $cmd atrings are deprecated and are ignored
  *
  * next args are passed as $cmd command line
- * e.g.: proc_run("ls","-la","/tmp");
  * or: proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
  * or: proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "include/create_shadowentry.php", $post_id);
  *
@@ -2000,11 +1994,6 @@ function proc_run($cmd){
        if (!$arr['run_cmd'] OR !count($args))
                return;
 
-       if (!get_config("system", "worker") OR (is_string($run_parameter) AND ($run_parameter != 'php'))) {
-               $a->proc_run($args);
-               return;
-       }
-
        $priority = PRIORITY_MEDIUM;
        $dont_fork = get_config("system", "worker_dont_fork");
 
@@ -2039,7 +2028,7 @@ function proc_run($cmd){
        }
 
        // Checking number of workers
-       $workers = q("SELECT COUNT(*) AS `workers` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");
+       $workers = q("SELECT COUNT(*) AS `workers` FROM `workerqueue` WHERE `executed` > '%s'", dbesc(NULL_DATE));
 
        // Get number of allowed number of worker threads
        $queues = intval(get_config("system", "worker_queues"));
@@ -2052,7 +2041,7 @@ function proc_run($cmd){
                return;
 
        // Now call the poller to execute the jobs that we just added to the queue
-       $args = array("php", "include/poller.php", "no_cron");
+       $args = array("include/poller.php", "no_cron");
 
        $a->proc_run($args);
 }
@@ -2386,38 +2375,6 @@ function get_itemcachepath() {
        return "";
 }
 
-function get_lockpath() {
-       $lockpath = get_config('system','lockpath');
-       if (($lockpath != "") AND App::directory_usable($lockpath)) {
-               // We have a lock path and it is usable
-               return $lockpath;
-       }
-
-       // We don't have a working preconfigured lock path, so we take the temp path.
-       $temppath = get_temppath();
-
-       if ($temppath != "") {
-               // To avoid any interferences with other systems we create our own directory
-               $lockpath = $temppath."/lock";
-               if (!is_dir($lockpath)) {
-                       mkdir($lockpath);
-               }
-
-               if (App::directory_usable($lockpath)) {
-                       // The new path is usable, we are happy
-                       set_config("system", "lockpath", $lockpath);
-                       return $lockpath;
-               } else {
-                       // We can't create a subdirectory, strange.
-                       // But the directory seems to work, so we use it but don't store it.
-                       return $temppath;
-               }
-       }
-
-       // Reaching this point means that the operating system is configured badly.
-       return "";
-}
-
 /**
  * @brief Returns the path where spool files are stored
  *