Example #1
0
 function controller_abtests($args, $output = "inline")
 {
     $user = User::Singleton();
     if (!($user->isLoggedIn() && $user->HasRole("ADMIN"))) {
         return ComponentManager::fetch("elation.accessviolation", NULL, "componentresponse");
     }
     $data = DataManager::singleton();
     $req = $this->root->request['args'];
     $vars['err_msg'] = "";
     if ($req['save_scope']) {
         // prepare to save new abtest - make sure we are not creating an active collision
         if ($req['status'] == 'active') {
             $sql = "SELECT * FROM userdata.abtest\n          WHERE status='active'\n          AND cobrand=:cobrand\n          AND effective_dt != :effective_dt";
             if ($req['save_scope'] != 'all') {
                 $sql .= " AND role = :role";
             }
             $query = DataManager::Query("db.abtests.abtest:nocache", $sql, array(":cobrand" => $req['cobrand'], ":effective_dt" => $req['effective_dt'], ":role" => $req['role']));
             if ($query->results) {
                 $vars['err_msg'] = "***Save Aborted -- Active Status Collision -- " . $req['cobrand'] . " " . $query->results[0]->effective_dt;
             }
         }
         if (!$vars['err_msg']) {
             // write new abtest group to database
             $roles = array($req['role']);
             if ($req['save_scope'] == 'all') {
                 $roles = array('dev', 'test', 'live', 'elation');
             }
             foreach ($roles as $role) {
                 DataManager::Query("db.abtests.abtest:nocache", "DELETE FROM userdata.abtest\n                          WHERE effective_dt=:effective_dt\n                          AND cobrand=:cobrand\n                          AND role=:role", array(":effective_dt" => $req["effective_dt"], ":cobrand" => $req["cobrand"], ":role" => $role));
                 foreach ($req['version'] as $k => $v) {
                     DataManager::Query("db.abtests.abtest:nocache", "INSERT INTO userdata.abtest\n                            SET version=:version,\n                               percent=:percent,\n                                effective_dt=:effective_dt,\n                                duration_days=:duration_days,\n                                status=:status,\n                                cobrand=:cobrand,\n                                config=:config,\n                                role=:role,\n                                is_base=:is_base", array(":version" => $v, ":percent" => $req['percent'][$k], ":effective_dt" => $req['effective_dt'], ":duration_days" => $req['duration'], ":status" => $req['status'], ":cobrand" => $req['cobrand'], ":config" => $req['config'][$k], ":role" => $role, ":is_base" => $req['isbase_position'] == $k ? '1' : '0'));
                 }
             }
         }
         //fall into new lookup---
     }
     $query = DataManager::Query("db.abtests.abtest:nocache", "SELECT * FROM userdata.abtest ORDER BY status, role, cobrand, effective_dt", array());
     $vars['last_version'] = 0;
     foreach ($query->results as $res) {
         $vars['abtest'][$res->status][$res->role][$res->cobrand][$res->effective_dt][] = array('Version' => $res->version, 'Percent' => $res->percent, 'Duration' => $res->duration_days, 'Config' => $res->config, 'IsBase' => $res->is_base);
         if ($vars['last_version'] < $res->version) {
             $vars['last_version'] = $res->version;
         }
     }
     $config = ConfigManager::singleton();
     $cobrands = $config->GetCobrandList('name');
     $cobrand_test = "";
     foreach ($cobrands['cobrand'] as $k => $v) {
         preg_match('#\\.([^.]+)#', $v->name, $matches);
         if ($cobrand_test != $matches[1]) {
             $vars['cobrands'][] = $matches[1];
         }
         $cobrand_test = $matches[1];
     }
     for ($i = 0; $i < 40; $i++) {
         $vars['dates'][] = date("Y-m-d", 86400 * $i + time());
     }
     $content = $this->GetTemplate("./abtests.tpl", $vars);
     if ($output == "ajax") {
         $ret["tf_debug_tab_abtests"] = $content;
     } else {
         $ret = $content;
     }
     return $ret;
 }
 /**
  * get the cobrandid and revision information
  *
  * @param $name, $role, $nocache
  * @return array
  */
 function GetCobrandidAndRevision($nocache = false)
 {
     $ret = array();
     if ($this->name && $this->role) {
         $query = DataManager::Query("db.config.version.{$this->name}.{$this->role}" . ($nocache ? ":nocache" : ""), "SELECT config.version.cobrandid, config.version.revision FROM config.version INNER JOIN config.cobrand on config.version.cobrandid=config.cobrand.cobrandid WHERE config.cobrand.name=:name and config.version.role=:role", array(":name" => $this->name, ":role" => $this->role));
         if ($query && $query->NumResults() == 1) {
             $version_info = $query->GetResult(0);
             $this->cobrandid = $version_info->cobrandid;
             $this->revision = $version_info->revision;
         } elseif ($nocache == true) {
             if ($this->AddRevisionByName($name, $role)) {
                 $this->GetCobrandidAndRevision($name, $role);
             }
         }
     }
     return array("cobrandid" => $this->cobrandid, "revision" => $this->revision);
 }
Example #3
0
 /**
  * This function will be called at script shutdown via PHP script shutdown.
  * It will loop through the errors and warning and send one email
  * and/or write the errors/warnings to the file IO.
  */
 public static function processShutdown()
 {
     global $webapp;
     // settings
     $sitecfg = array("logger" => Configmanager::get("logger"));
     $sitecfg = $sitecfg["logger"]["email"] && $sitecfg["logger"]["file"] ? $sitecfg : self::getDefaultLoggerConfig();
     // email section
     $level_setting = self::convertLevelToNumeric($sitecfg["logger"]["email"]["level"]);
     $interval = $sitecfg["logger"]["email"]["interval"] > 0 ? $sitecfg["logger"]["email"]["interval"] : 10;
     // default to 10 minutes
     if ($level_setting > 0 && $lvl <= $level_setting && $sitecfg["logger"]["email"]["email_to"]) {
         $data_mgr = DataManager::singleton();
         // loop through them and send the ones that should be sent
         $email_msg = "";
         foreach (self::$log_emails as $email) {
             if ($email["level"] <= $level_setting) {
                 $cache_val = DataManager::Query("memcache.data", $email["cache_key"]);
                 if (time() - $cache_val["sent_timestamp"] >= $interval * 60) {
                     $num_times = $cache_val["count"] + 1;
                     $header = "From: " . $_SERVER["SERVER_ADMIN"] . "\n";
                     $subject = "Warning/Error message from " . $_SERVER["SERVER_ADMIN"];
                     // append the # of times this warning/error has occurred
                     $email_msg .= self::NEWLINE . self::NEWLINE . self::NEWLINE . "Number of times happened since last email = " . $num_times . self::NEWLINE . $email["content"];
                     if ($data_mgr) {
                         $cache_val["count"] = 0;
                         $cache_val["sent_timestamp"] = time();
                         DataManager::QueryInsert("memcache.data", $email["cache_key"], $cache_val);
                     }
                 } else {
                     if ($data_mgr) {
                         $cache_val["count"] += 1;
                         DataManager::QueryInsert("memcache.data", $email["cache_key"], $cache_val);
                     }
                 }
             }
         }
         if ($email_msg) {
             mail($sitecfg["logger"]["email"]["email_to"], $subject, $email_msg, $header);
         }
     }
     // log file to IO
     $level_setting = self::convertLevelToNumeric($sitecfg["logger"]["file"]["level"]);
     if ($level_setting > 0 && $sitecfg["logger"]["file"]["path"]) {
         $file_msg = "";
         foreach (self::$log_files as $file) {
             if ($file["level"] <= $level_setting) {
                 $file_msg .= $file["content"] . self::NEWLINE;
             }
         }
         $folder = rtrim($sitecfg["logger"]["file"]["path"], "/");
         $fname = $folder . "/uilogger." . date("YmdH") . "0000";
         // create folder if not already there
         if (file_exists($folder) == false) {
             mkdir($folder, 0777);
         }
         $file_exist = false;
         if (file_exists($fname) == false) {
             $file_exist = is_writable($folder) && touch($fname);
         } else {
             $file_exist = true;
         }
         if ($file_exist && is_writable($fname)) {
             file_put_contents($fname, $file_msg, FILE_APPEND);
         }
     }
     $timestats = array("page" => any($webapp->components->pagecfg["pagename"], $webapp->request["path"]), "total" => Profiler::GetTime("WebApp"));
     if (($time = Profiler::GetTime("QPMWrapper:Query()")) != NULL) {
         $timestats["qpm"] = $time;
     }
     if (($time = Profiler::GetTime("QPMThriftWrapper:Query()")) != NULL) {
         $timestats["qpm"] += $time;
     }
     if (($time = Profiler::GetTime("QPMWrapper:Query() - first byte")) != NULL) {
         $timestats["qpmfirstbyte"] = $time;
     }
     if (($time = Profiler::GetTime("DBWrapper:Query()")) != NULL) {
         $timestats["db"] = $time;
     }
     if (($time = Profiler::GetTime("WebApp::TimeToDisplay")) != NULL) {
         $timestats["firstbyte"] = $time;
     }
     if (($time = Profiler::GetTime("WebApp::Display() - Conteg")) != NULL) {
         $timestats["output"] = $time;
     }
     if (($time = Profiler::GetTime("Conteg::compress")) != NULL) {
         $timestats["compress"] = $time;
     }
     if (($time = Profiler::GetTime("Postprocessing")) != NULL) {
         $timestats["postprocessing"] = $time;
     }
     DataManager::Query("stats.default.blah:nocache", "www.timing.total", $timestats);
     $data = DataManager::singleton();
     if ($data) {
         $data->Quit();
         // shutdown to make sure sockets are flushed
     }
 }
Example #4
0
 /**
  * Test deleting all data from a table
  *
  * @dataProvider providerOfTables
  */
 public function testDelete($table)
 {
     $q = DataManager::QueryDelete($table["keyprefix"] . ".select.all", $table["name"]);
     $this->assertTrue($q, "Delete all rows from '{$table["name"]}'");
     $qcount = DataManager::Query($table["keyprefix"] . "count", "SELECT COUNT(*) AS cnt FROM {$table["name"]}");
     $this->assertEquals($qcount->rows[0]->cnt, 0, "Check no rows still exist in '{$table["name"]}'");
 }