Fixes a bug in accepting invitations to groups, fixes when MediaUpdater checks for email and videos, a=chris

Chris Pollett [2015-08-19 22:Aug:th]
Fixes a bug in accepting invitations to groups, fixes when MediaUpdater checks for email and videos, a=chris
Filename
src/controllers/CrawlController.php
src/controllers/components/SocialComponent.php
src/executables/MediaUpdater.php
src/index.php
diff --git a/src/controllers/CrawlController.php b/src/controllers/CrawlController.php
index da76d5996..ef1e1765f 100644
--- a/src/controllers/CrawlController.php
+++ b/src/controllers/CrawlController.php
@@ -340,6 +340,9 @@ class CrawlController extends Controller implements CrawlConstants,
         $response = [];
         $response['MEDIA_MODE'] = (isset($profile['MEDIA_MODE'])) ?
             $profile['MEDIA_MODE'] : "name_server";
+        $response['SEND_MAIL_MEDIA_UPDATER'] =
+            (isset($profile['SEND_MAIL_MEDIA_UPDATER'])) ?
+            $profile['SEND_MAIL_MEDIA_UPDATER'] : false;
         echo L\webencode(serialize($response));
     }
     /**
diff --git a/src/controllers/components/SocialComponent.php b/src/controllers/components/SocialComponent.php
index 15a077e5e..cb1434e60 100644
--- a/src/controllers/components/SocialComponent.php
+++ b/src/controllers/components/SocialComponent.php
@@ -144,7 +144,7 @@ class SocialComponent extends Component implements CrawlConstants
                 $_SESSION['USER_ID']);
             if (isset($group['OWNER_ID'] ) &&
                 ($group['OWNER_ID'] == $_SESSION['USER_ID'] ||
-                ($_SESSION['USER_ID'] == ROOT_ID && $_REQUEST['arg'] ==
+                ($_SESSION['USER_ID'] == C\ROOT_ID && $_REQUEST['arg'] ==
                 "changeowner"))) {
                 $name = $group['GROUP_NAME'];
                 $data['CURRENT_GROUP']['name'] = $name;
diff --git a/src/executables/MediaUpdater.php b/src/executables/MediaUpdater.php
index 6e331008f..a6c231f56 100644
--- a/src/executables/MediaUpdater.php
+++ b/src/executables/MediaUpdater.php
@@ -81,6 +81,13 @@ class MediaUpdater implements CrawlConstants, MediaConstants
      * @var int
      */
     public $update_time;
+    /**
+     * If true then it is assumed that mail should be
+     * sent using a media updater rather than from within the web app
+     *
+     * @var bool
+     */
+    public $mail_mode;
     /**
      * Controls whether media updating should be viewed as only occurring
      * on the name server or should it be viewed as a distributed process
@@ -107,6 +114,7 @@ class MediaUpdater implements CrawlConstants, MediaConstants
         $this->retry_time = 0;
         $this->update_time = 0;
         $this->media_mode = "name_server";
+        $this->media_mode = false;
         $this->mail_server = new MailServer(C\MAIL_SENDER, C\MAIL_SERVER,
             C\MAIL_SERVERPORT, C\MAIL_USERNAME, C\MAIL_PASSWORD,
             C\MAIL_SECURITY);
@@ -139,8 +147,13 @@ class MediaUpdater implements CrawlConstants, MediaConstants
             $start_time = microtime(true);
             $this->getUpdateProperties();
             $this->newsUpdate();
-            $this->videoUpdate();
-            $this->sendGroupNotificationEmailsInBatches();
+            if ($this->media_mode == 'distributed') {
+                $this->videoUpdate();
+            }
+            if ($this->media_mode == 'distributed' ||
+                $this->mail_mode ) {
+                $this->sendGroupNotificationEmailsInBatches();
+            }
             $sleep_time = max(0, ceil(self::MINIMUM_UPDATE_LOOP_TIME -
                     L\changeInMicrotime($start_time)));
             if ($sleep_time > 0) {
@@ -166,11 +179,18 @@ class MediaUpdater implements CrawlConstants, MediaConstants
         if (isset($pre_properties[0][self::PAGE])) {
             $properties =
                 unserialize(L\webdecode($pre_properties[0][self::PAGE]));
-            if(isset($properties['MEDIA_MODE'])) {
+            if (isset($properties['MEDIA_MODE'])) {
                 $this->media_mode = $properties['MEDIA_MODE'];
                 L\crawlLog("...Setting media mode to: " .
                     $properties['MEDIA_MODE']);
             }
+            if (isset($properties['SEND_MAIL_MEDIA_UPDATER'])) {
+                $this->mail_mode = (
+                    $properties['SEND_MAIL_MEDIA_UPDATER']== "true") ?
+                    true : false;
+                L\crawlLog("...Setting mail mode to: " .
+                    (($this->mail_mode) ? "true" : "false"));
+            }
         }
         L\crawlLog("Done checking Name Server for Media Updater properties");
     }
@@ -543,7 +563,7 @@ class MediaUpdater implements CrawlConstants, MediaConstants
         L\crawlLog("Checking for mailer files to be sent out...");
         $current_machine = $this->sourceModel->getCurrentMachine();
         if ($current_machine == L\crawlHash(C\NAME_SERVER) &&
-            C\MEDIA_MODE != 'distributed') {
+            C\MEDIA_MODE == 'distributed') {
             $mail_directory = C\WORK_DIRECTORY . self::MAIL_FOLDER;
             if(!file_exists($mail_directory)) { return; }
             $files = glob($mail_directory."/*.txt");
diff --git a/src/index.php b/src/index.php
index adb81acab..468843daa 100755
--- a/src/index.php
+++ b/src/index.php
@@ -137,9 +137,6 @@ function bootstrap()
     }
     //upgrade manipulations might mess with globale locale, so set it back here
     L\setLocaleObject($locale_tag);
-    if (file_exists(C\APP_DIR."/index.php")) {
-        require_once C\APP_DIR."/index.php";
-    }
     /**
      * Loads controller responsible for calculating
      * the data needed to render the scene
@@ -206,7 +203,8 @@ function configureRewrites()
     /**
      * Now look for and handle routes
      */
-    $script_path = substr($_SERVER['PHP_SELF'], 0, -strlen("index.php"));
+    $index_php = "index.php";
+    $script_path = substr($_SERVER['PHP_SELF'], 0, -strlen($index_php));
     if($_SERVER['QUERY_STRING'] == "") {
         $request_script = rtrim(
             substr($_SERVER['REQUEST_URI'], strlen($script_path)), "?");
@@ -214,8 +212,8 @@ function configureRewrites()
         $request_script = substr($_SERVER['REQUEST_URI'], strlen($script_path),
             -strlen($_SERVER['QUERY_STRING']) -  1);
     }
-    $request_script = ($request_script == "") ? "index.php" : $request_script;
-    if(in_array($request_script, ['', 'index.php'])) {
+    $request_script = ($request_script == "") ? $index_php : $request_script;
+    if(in_array($request_script, ['', $index_php])) {
         return;
     }
     $request_parts = explode("/", $request_script);
ViewGit