]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
Merge pull request #3849 from annando/forum-exclamation
[friendica.git] / boot.php
index ac6cbc95508c5bc236848eca8693a376d1ad5ba8..cdd71719a6e46035d1bbfa6926c404f7302dcb4b 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -41,9 +41,9 @@ require_once 'include/poller.php';
 
 define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Asparagus');
-define ( 'FRIENDICA_VERSION',      '3.5.3-dev' );
+define ( 'FRIENDICA_VERSION',      '3.6-dev' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1234      );
+define ( 'DB_UPDATE_VERSION',      1235      );
 
 /**
  * @brief Constant with a HTML line break.
@@ -229,8 +229,9 @@ define('PROTOCOL_UNKNOWN',         0);
 define('PROTOCOL_DFRN',            1);
 define('PROTOCOL_DIASPORA',        2);
 define('PROTOCOL_OSTATUS_SALMON',  3);
-define('PROTOCOL_OSTATUS_FEED',    4);
-define('PROTOCOL_GS_CONVERSATION', 5);
+define('PROTOCOL_OSTATUS_FEED',    4); // Deprecated
+define('PROTOCOL_GS_CONVERSATION', 5); // Deprecated
+define('PROTOCOL_SPLITTED_CONV',   6);
 /** @}*/
 
 /**
@@ -320,6 +321,8 @@ define ( 'NOTIFY_TAGSHARE', 0x0100 );
 define ( 'NOTIFY_POKE',     0x0200 );
 define ( 'NOTIFY_SHARE',    0x0400 );
 
+define ( 'SYSTEM_EMAIL',    0x4000 );
+
 define ( 'NOTIFY_SYSTEM',   0x8000 );
 /* @}*/
 
@@ -391,6 +394,7 @@ define ( 'ACTIVITY_POST',        NAMESPACE_ACTIVITY_SCHEMA . 'post' );
 define ( 'ACTIVITY_UPDATE',      NAMESPACE_ACTIVITY_SCHEMA . 'update' );
 define ( 'ACTIVITY_TAG',         NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
 define ( 'ACTIVITY_FAVORITE',    NAMESPACE_ACTIVITY_SCHEMA . 'favorite' );
+define ( 'ACTIVITY_UNFAVORITE',  NAMESPACE_ACTIVITY_SCHEMA . 'unfavorite' );
 define ( 'ACTIVITY_SHARE',       NAMESPACE_ACTIVITY_SCHEMA . 'share' );
 define ( 'ACTIVITY_DELETE',      NAMESPACE_ACTIVITY_SCHEMA . 'delete' );
 
@@ -506,6 +510,11 @@ function startup() {
  */
 function get_app() {
        global $a;
+
+       if (empty($a)) {
+               $a = new App(dirname(__DIR__));
+       }
+
        return $a;
 }
 
@@ -587,7 +596,12 @@ function is_ajax() {
        return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
 }
 
-function check_db() {
+/**
+ * @brief Function to check if request was an AJAX (xmlhttprequest) request.
+ *
+ * @param $via_worker boolean Is the check run via the poller?
+ */
+function check_db($via_worker) {
 
        $build = get_config('system', 'build');
        if (!x($build)) {
@@ -595,7 +609,10 @@ function check_db() {
                $build = DB_UPDATE_VERSION;
        }
        if ($build != DB_UPDATE_VERSION) {
-               proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php');
+               // When we cannot execute the database update via the worker, we will do it directly
+               if (!proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php') && $via_worker) {
+                       update_db(get_app());
+               }
        }
 }
 
@@ -887,8 +904,14 @@ function login($register = false, $hiddens = false) {
  * @brief Used to end the current process, after saving session state.
  */
 function killme() {
+       global $session_exists;
+
        if (!get_app()->is_backend()) {
-               session_write_close();
+               if (!$session_exists) {
+                       session_abort();
+               } else {
+                       session_write_close();
+               }
        }
 
        exit();
@@ -947,6 +970,10 @@ function public_contact() {
  * @return int|bool visitor_id or false
  */
 function remote_user() {
+       // You cannot be both local and remote
+       if (local_user()) {
+               return false;
+       }
        if ((x($_SESSION, 'authenticated')) && (x($_SESSION, 'visitor_id'))) {
                return intval($_SESSION['visitor_id']);
        }
@@ -1016,6 +1043,8 @@ function get_max_import_size() {
  *
  * @hooks 'proc_run'
  *     array $arr
+ *
+ * @return boolean "false" if proc_run couldn't be executed
  */
 function proc_run($cmd) {
 
@@ -1025,7 +1054,7 @@ function proc_run($cmd) {
 
        $args = array();
        if (!count($proc_args)) {
-               return;
+               return false;
        }
 
        // Preserve the first parameter
@@ -1051,7 +1080,7 @@ function proc_run($cmd) {
 
        call_hooks("proc_run", $arr);
        if (!$arr['run_cmd'] || ! count($args)) {
-               return;
+               return true;
        }
 
        $priority = PRIORITY_MEDIUM;
@@ -1078,18 +1107,23 @@ function proc_run($cmd) {
        $parameters = json_encode($argv);
        $found = dba::exists('workerqueue', array('parameter' => $parameters, 'done' => false));
 
+       // Quit if there was a database error - a precaution for the update process to 3.5.3
+       if (dba::errorNo() != 0) {
+               return false;
+       }
+
        if (!$found) {
                dba::insert('workerqueue', array('parameter' => $parameters, 'created' => $created, 'priority' => $priority));
        }
 
        // Should we quit and wait for the poller to be called as a cronjob?
        if ($dont_fork) {
-               return;
+               return true;
        }
 
        // If there is a lock then we don't have to check for too much worker
        if (!Lock::set('poller_worker', 0)) {
-               return;
+               return true;
        }
 
        // If there are already enough workers running, don't fork another one
@@ -1097,13 +1131,15 @@ function proc_run($cmd) {
        Lock::remove('poller_worker');
 
        if ($quit) {
-               return;
+               return true;
        }
 
        // Now call the poller to execute the jobs that we just added to the queue
        $args = array("include/poller.php", "no_cron");
 
        $a->proc_run($args);
+
+       return true;
 }
 
 function current_theme() {