public function getNextTestSession($projectGroupId, $projectId, $productId, $environmentId, $imageId)
 {
     $qa_generic = sfConfig::get("app_table_qa_generic");
     $query = Doctrine_Manager::getInstance()->getCurrentConnection();
     $result = $query->execute("\n\t\t\tSELECT ts.id, ts.name, ts.status, ts.test_objective, ts.qa_summary, ts.user_id, ts.created_at, ts.editor_id, ts.updated_at, ts.project_release, ts.project_milestone,\n\t\t\t\tts.issue_summary, ts.status, ts.published, ts.configuration_id, ts.campaign_checksum\n\t\t\t\tFROM " . $qa_generic . ".test_session ts\n\t\t\t\tJOIN " . $qa_generic . ".configuration c ON c.id = ts.configuration_id\n\t\t\t\tJOIN " . $qa_generic . ".project_to_product ptp ON ptp.id = c.project_to_product_id\n\t\t\t\tWHERE ptp.project_group_id = " . $projectGroupId . "\n\t\t\t\tAND ptp.project_id = " . $projectId . "\n\t\t\t\tAND ptp.product_id = " . $productId . "\n\t\t\t\tAND c.test_environment_id = " . $environmentId . "\n\t\t\t\tAND c.image_id = " . $imageId . "\n\t\t\t\tAND ts.created_at > '" . $this->getCreatedAt() . "'\n\t\t\t\tORDER BY ts.created_at ASC\n\t\t\t\tLIMIT 1\n\t\t");
     $array = $result->fetchAll();
     if (count($array) > 0) {
         $testSession = new TestSession();
         $testSession->fromArray($array[0]);
         return $testSession;
     }
     return null;
 }
Exemplo n.º 2
0
 /**
  * Return a CSSContentParser for the most recent content.
  *
  * @return CSSContentParser
  */
 public function cssParser()
 {
     if (!$this->cssParser) {
         $this->cssParser = new CSSContentParser($this->mainSession->lastContent());
     }
     return $this->cssParser;
 }
Exemplo n.º 3
0
 public function setUp()
 {
     $this->di = new \Phalcon\DI\FactoryDefault();
     $this->di->setShared('db', function () {
         $db = new TestDatabase();
         $db->cleanUp();
         $db->constructUsers();
         return $db;
     });
     $this->di->setShared('session', function () {
         $adapter = new TestSession();
         $adapter->start();
         return $adapter;
     });
     $this->di->set('auth', new \AD\Auth\Security\Auth(new \Phalcon\Config(array('session_key' => 'testkey', 'hash_key' => 'hashkey', 'hash_method' => 'sha256')), '\\TestUser'));
     \Phalcon\DI::setDefault($this->di);
 }
Exemplo n.º 4
0
function get_returns($sid, $hash, $pass)
{
    if (!authorize_WS($pass)) {
        return false;
    }
    $session = TestSession::from_property(array("id" => $sid, "hash" => $hash), false);
    if ($session == null) {
        return false;
    }
    $return = TestSessionReturn::from_property(array("TestSession_id" => $sid));
    $result = array();
    foreach ($return as $ret) {
        $result[$ret->name] = $ret->value;
    }
    return json_encode($result);
}
Exemplo n.º 5
0
function get_returns($sid, $hash, $pass, $wid)
{
    if (!authorize_WS($pass)) {
        return -1;
    }
    $workspace = UserWorkspace::from_mysql_id($wid);
    if ($workspace != null) {
        mysql_select_db($workspace->db_name);
    }
    $session = TestSession::from_property(array("id" => $sid, "hash" => $hash), false);
    if ($session == null) {
        return false;
    }
    $return = TestSessionReturn::from_property(array("TestSession_id" => $sid));
    $result = array();
    foreach ($return as $ret) {
        $result[$ret->name] = $ret->value;
    }
    return json_encode($result);
}
//vars
$name = "concerto.table.query";
$db = User::get_current_db();
if (array_key_exists("db", $_POST)) {
    $workspace_id = $_POST['db'];
}
$table_name = "";
if (array_key_exists("table_name", $_POST)) {
    $table_name = $_POST['table_name'];
}
$type = "SELECT";
if (array_key_exists("type", $_POST)) {
    $type = $_POST['type'];
}
$ws = UserWorkspace::from_property(array("db_name" => $db), false);
TestSession::change_db($ws->id);
$table = Table::from_property(array("name" => $table_name), false);
$table_columns = array();
if ($table != null) {
    $table_columns = $table->get_columns();
}
$select_section = array(array("v" => 0, "w0" => "*", "c" => "*"));
$select_section = json_encode($select_section);
if (array_key_exists('select_section', $_POST)) {
    $select_section = $_POST['select_section'];
}
$select_section = json_decode($select_section);
if (array_key_exists("select_section_add", $_POST) && $_POST['select_section_add'] == 1) {
    array_push($select_section, json_decode(json_encode(array("v" => 0, "w0" => "*", "c" => "*"))));
}
$where_section = array();
Exemplo n.º 7
0
 /**
  * Process the form to add a new test session.
  *
  * @param sfWebRequest $request
  * @param ImportForm $form
  */
 protected function processAdd(sfWebRequest $request, ImportForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         // Get sent values and uploaded files
         $values = $form->getValues();
         $files = $request->getFiles();
         // Retrieve values from form
         $projectGroupId = $values["project_group_id"];
         $projectId = $values["project"];
         $productId = $values["product"];
         $date = $values["date"] . " " . date("H:i:s");
         $buildId = $values["build_id"];
         $testType = $values["testset"];
         $title = $values["name"];
         $environmentForm = $form->getValue("environmentForm");
         $imageForm = $form->getValue("imageForm");
         $userId = $this->getUser()->getGuardUser()->getId();
         $buildSlug = MiscUtils::slugify($buildId);
         $testTypeSlug = MiscUtils::slugify($testType);
         // Customize database connection to begin a transactionnal query
         $conn = Doctrine_Manager::getInstance()->getConnection("qa_generic");
         $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, FALSE);
         $conn->beginTransaction();
         $project = Doctrine_Core::getTable("Project")->getBasicProjectById($projectId);
         $product = Doctrine_Core::getTable("ProductType")->getBasicProductById($productId);
         // Create a new relationship between project group, project and product if needed
         $projectToProductId = Doctrine_Core::getTable("ProjectToProduct")->getProjectToProductId($projectGroupId, $projectId, $productId);
         if ($projectToProductId == null) {
             $projectToProduct = new ProjectToProduct();
             $projectToProduct->setProjectGroupId($projectGroupId);
             $projectToProduct->setProjectId($projectId);
             $projectToProduct->setProductId($productId);
             $projectToProduct->save($conn);
             $projectToProductId = $projectToProduct->getId();
         }
         // Create a new environment if needed
         $environment = Doctrine_Core::getTable("TestEnvironment")->findByArray($environmentForm);
         if ($environment == null) {
             // Add new environment
             $environment = new TestEnvironment();
             $environment->setName($environmentForm["name"]);
             $environment->setDescription($environmentForm["description"]);
             $environment->setCpu($environmentForm["cpu"]);
             $environment->setBoard($environmentForm["board"]);
             $environment->setGpu($environmentForm["gpu"]);
             $environment->setOtherHardware($environmentForm["other_hardware"]);
             // Check if its slug does not already exist and generate a new one if needed
             $slug = MiscUtils::slugify($environmentForm["name"]);
             $size = 1;
             while (Doctrine_Core::getTable("TestEnvironment")->checkSlug($slug)) {
                 $slug = MiscUtils::slugify($environmentForm["name"]) . substr(microtime(), -$size);
                 $size++;
             }
             $environment->setNameSlug($slug);
             $environment->save($conn);
             // Convert object into associative array
             $environment = $environment->toArray();
         }
         // Create a new image if needed
         $image = Doctrine_Core::getTable("Image")->findByArray($imageForm);
         if ($image == null) {
             // Add new image
             $image = new Image();
             $image->setName($imageForm["name"]);
             $image->setDescription($imageForm["description"]);
             $image->setOs($imageForm["os"]);
             $image->setDistribution($imageForm["distribution"]);
             $image->setVersion($imageForm["version"]);
             $image->setKernel($imageForm["kernel"]);
             $image->setArchitecture($imageForm["architecture"]);
             $image->setOtherFw($imageForm["other_fw"]);
             $image->setBinaryLink($imageForm["binary_link"]);
             $image->setSourceLink($imageForm["source_link"]);
             // Check if its slug does not already exist and generate a new one if needed
             $slug = MiscUtils::slugify($imageForm["name"]);
             $size = 1;
             while (Doctrine_Core::getTable("Image")->checkSlug($slug)) {
                 $slug = MiscUtils::slugify($imageForm["name"]) . substr(microtime(), -$size);
                 $size++;
             }
             $image->setNameSlug(MiscUtils::slugify($slug));
             $image->save($conn);
             // Convert object into associative array
             $image = $image->toArray();
         }
         // Create a new configuration relationship if needed
         $configurationId = Doctrine_Core::getTable("Configuration")->getConfigurationId($projectToProductId, $environment["id"], $image["id"]);
         if ($configurationId == null) {
             $configuration = new Configuration();
             $configuration->setProjectToProductId($projectToProductId);
             $configuration->setTestEnvironmentId($environment["id"]);
             $configuration->setImageId($image["id"]);
             $configuration->save($conn);
             $configurationId = $configuration->getId();
         }
         // Add the new session into DB
         $testSession = new TestSession();
         if (empty($title)) {
             $title = $product["name"] . " Test Report: " . $environment["name"] . " " . $image["name"] . " " . substr($date, 0, -3);
             if (!empty($buildId)) {
                 $title .= " Build ID: " . $buildId;
             }
         }
         $testSession->setBuildId($buildId);
         $testSession->setTestset($testType);
         $testSession->setName($title);
         $testSession->setUserId($userId);
         $testSession->setCreatedAt($date);
         $testSession->setUpdatedAt($date);
         $testSession->setStatus(2);
         $testSession->setPublished(0);
         $testSession->setConfigurationId($configurationId);
         $testSession->setBuildSlug($buildSlug);
         $testSession->setTestsetSlug($testTypeSlug);
         $testSession->save($conn);
         $testSessionId = $testSession->getId();
         $tableName = Doctrine_Core::getTable("TableName")->findOneByName("test_session");
         $tableNameId = $tableName->getId();
         // Concatenate directory path
         $dir_path = sfConfig::get('sf_upload_dir') . "/testsession_" . $testSessionId;
         // Upload attachments and result files
         foreach ($files["upload"] as $key => $file) {
             $fileName = $file['name'];
             $fileSize = $file['size'];
             $fileType = $file['type'];
             $fileError = $file['error'];
             $fileChecksum = sha1_file($file["tmp_name"]);
             // Check file error and file size
             if (!$fileError and $fileSize <= sfConfig::get('app_max_file_size', '10000000')) {
                 if (!is_dir($dir_path)) {
                     mkdir($dir_path, 0777, true);
                 }
                 $dest_path = $dir_path . "/" . $fileName;
                 // Move file to uploads directory
                 move_uploaded_file($file['tmp_name'], $dest_path);
                 // If it is an XML file, parse it and fill qa_generic database
                 if (preg_match("#\\.xml *\$#i", $fileName) || preg_match("#\\.csv *\$#i", $fileName)) {
                     // Fill qa_generic database
                     if ($err_code = Import::file($dest_path, $testSessionId, $configurationId, $conn)) {
                         $error_message = Import::getImportErrorMessage($err_code);
                         MiscUtils::deleteDir($dir_path);
                         $conn->rollback();
                         $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                         $this->getUser()->setFlash("error", "Invalid file content on " . $fileName . " : " . $error_message);
                         $this->redirect("add_report", array());
                     }
                 } else {
                     MiscUtils::deleteDir($dir_path);
                     $conn->rollback();
                     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                     $this->getUser()->setFlash("error", "Invalid file format : only XML and CSV format are supported");
                     $this->redirect("add_report", array());
                 }
                 $web_path = "/uploads" . "/testsession_" . $testSessionId . "/" . $fileName;
                 $fileAttachment = new FileAttachment();
                 $fileAttachment->setName($fileName);
                 $fileAttachment->setUserId($userId);
                 $fileAttachment->setUploadedAt(date("Y-m-d H:i:s"));
                 $fileAttachment->setFilename($fileName);
                 $fileAttachment->setFileSize($fileSize);
                 $fileAttachment->setFileMimeType($fileType);
                 $fileAttachment->setLink($web_path);
                 $fileAttachment->setChecksum($fileChecksum);
                 $fileAttachment->setTableNameId($tableNameId);
                 $fileAttachment->setTableEntryId($testSessionId);
                 $fileAttachment->setCategory(1);
                 $fileAttachment->save($conn);
             } else {
                 MiscUtils::deleteDir($dir_path);
                 $conn->rollback();
                 $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                 $this->getUser()->setFlash("error", "File size limit reached");
                 $this->redirect("add_report", array());
             }
         }
         $conn->commit();
         $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
         $this->redirect("finalize_report", array("project" => $project["name_slug"], "product" => $product["name_slug"], "environment" => $environment["name_slug"], "image" => $image["name_slug"], "id" => $testSessionId));
     }
 }
Exemplo n.º 8
0
 public static function reset_db()
 {
     CustomSection::create_db(true);
     CustomSectionVariable::create_db(true);
     DS_Module::create_db(true);
     DS_Right::create_db(true);
     DS_Sharing::create_db(true);
     DS_TestSectionType::create_db(true);
     DS_UserInstitutionType::create_db(true);
     Setting::create_db(true);
     Table::create_db(true);
     TableColumn::create_db(true);
     Template::create_db(true);
     Test::create_db(true);
     TestSection::create_db(true);
     TestSectionValue::create_db(true);
     TestSession::create_db(true);
     TestSessionReturn::create_db(true);
     TestTemplate::create_db(true);
     TestVariable::create_db(true);
     User::create_db(true);
     UserGroup::create_db(true);
     UserType::create_db(true);
     UserTypeRight::create_db(true);
 }
Exemplo n.º 9
0
 public function delete_sessions()
 {
     $sessions = TestSession::from_property(array("Test_id" => $this->id));
     foreach ($sessions as $session) {
         $session->remove();
     }
 }
 public function get_TestSession()
 {
     return TestSession::from_mysql_id($this->TestSession_id);
 }
 public function __construct()
 {
     if (self::$session_id === 0) {
         self::$session_id = bin2hex(openssl_random_pseudo_bytes(16));
     }
 }
Exemplo n.º 12
0
}
$sid = null;
if (array_key_exists("sid", $_POST)) {
    $sid = $_POST['sid'];
}
$hash = null;
if (array_key_exists("hash", $_POST)) {
    $hash = $_POST['hash'];
}
$values = null;
if (array_key_exists("values", $_POST)) {
    $values = $_POST['values'];
}
$btn_name = null;
if (array_key_exists("btn_name", $_POST)) {
    $btn_name = $_POST['btn_name'];
}
$debug = null;
if (array_key_exists("debug", $_POST)) {
    $debug = $_POST['debug'];
}
$code = null;
if (array_key_exists("code", $_POST)) {
    $code = $_POST['code'];
}
$resume_from_last_template = 0;
if (array_key_exists("resume_from_last_template", $_POST)) {
    $resume_from_last_template = $_POST['resume_from_last_template'];
}
$result = TestSession::forward($tid, $sid, $hash, $values, $btn_name, $debug, $time, $wid, $resume_from_last_template == 1, $code);
echo json_encode($result);
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
if (!isset($ini)) {
    require_once '../../Ini.php';
    $ini = new Ini();
}
$logged_user = User::get_logged_user();
if ($logged_user == null) {
    echo json_encode(array("result" => -1));
    exit;
}
$session = TestSession::start_new($_POST['Test_id']);
$test = $session->get_Test();
if ($test == null) {
    echo json_encode(array("result" => -2));
    exit;
}
$section = TestSection::from_property(array("Test_id" => $test->id, "counter" => $_POST['counter']), false);
$close = true;
$next_section = $section->get_next_TestSection();
$next_counter = 0;
if ($next_section != null) {
    $next_counter = $next_section->counter;
}
$result = $session->debug_syntax($section->id, $close);
$session->remove();
echo json_encode(array("result" => 0, "response" => $result, "next_counter" => $next_counter));
Exemplo n.º 14
0
 public static function forward($tid, $sid, $hash, $values, $btn_name, $debug, $time, $resume_from_last_template = false)
 {
     $session = null;
     $result = array();
     if ($sid != null && $hash != null) {
         $session = TestSession::authorized_session($sid, $hash);
         if ($session != null) {
             if ($values == null) {
                 $values = array();
             }
             if ($btn_name != null) {
                 array_push($values, json_encode(array("name" => "LAST_PRESSED_BUTTON_NAME", "value" => $btn_name)));
             }
             if (Ini::$timer_tamper_prevention && $session->time_limit > 0 && $time - $session->time_tamper_prevention - Ini::$timer_tamper_prevention_tolerance > $session->time_limit) {
                 if ($session->debug == 1) {
                     TestSession::unregister($session->id);
                 } else {
                     $session->close();
                 }
                 $result = array("data" => array("HASH" => $hash, "TIME_LIMIT" => 0, "HTML" => "", "TEST_ID" => 0, "TEST_SESSION_ID" => $sid, "STATUS" => TestSession::TEST_SESSION_STATUS_TAMPERED, "TEMPLATE_ID" => 0, "HEAD" => "", "FINISHED" => 1));
                 if ($session->debug == 1) {
                     $result["debug"] = array("code" => 0, "return" => "", "output" => "");
                 }
             } else {
                 if (!$resume_from_last_template) {
                     $result = $session->resume($values);
                 } else {
                     $ts = TestSection::from_mysql_id($session->Template_TestSection_id);
                     if ($ts == null) {
                         $result = $session->resume($values);
                     } else {
                         $result = $session->run_Test($ts->counter, $values);
                     }
                 }
             }
         } else {
             $result = array("data" => array("HASH" => $hash, "TIME_LIMIT" => 0, "HTML" => "", "TEST_ID" => 0, "TEST_SESSION_ID" => $sid, "STATUS" => TestSession::TEST_SESSION_STATUS_TAMPERED, "TEMPLATE_ID" => 0, "HEAD" => "", "FINISHED" => 1), "debug" => array("code" => 0, "return" => "", "output" => ""));
         }
     } else {
         if ($tid != null) {
             if ($debug == 1) {
                 $debug = true;
             } else {
                 $debug = false;
             }
             $session = TestSession::start_new($tid, $debug);
             if ($values == null) {
                 $values = array();
             }
             $test = $session->get_Test();
             if ($test != null) {
                 $values = $test->verified_input_values($values);
             } else {
                 $result = array("data" => array("HASH" => $hash, "TIME_LIMIT" => 0, "HTML" => "", "TEST_ID" => $tid, "TEST_SESSION_ID" => $sid, "STATUS" => TestSession::TEST_SESSION_STATUS_TAMPERED, "TEMPLATE_ID" => 0, "HEAD" => "", "FINISHED" => 1), "debug" => array("code" => 0, "return" => "", "output" => ""));
                 return $result;
             }
             $result = $session->run_test(null, $values);
         }
     }
     return $result;
 }
Exemplo n.º 15
0
if (substr($sms->suffix, 0, strlen(REATESTER_SMS_PREFIX)) != REATESTER_SMS_PREFIX) {
    $sms->put(sprintf(SMS_REPLY_INVALID_PREFIX, $sms->suffix));
    reply();
}
$sms->suffix = trim(substr($sms->suffix, strlen(REATESTER_SMS_PREFIX)));
$sms->status = SMS_STATUS_PROCESSING;
$sms->put();
/************************************************************************************
 Распознавание суффикса
************************************************************************************/
if (strlen($sms->suffix) != REATESTER_SMS_CHAL_LENGTH) {
    $sms->status = SMS_STATUS_INVALID_SUFFIX_FORMAT;
    $sms->put();
    reply(sprintf(SMS_REPLY_WRONG_SUFFIX_FORMAT, $sms->msg));
}
$session = TestSession::get("WHERE sms_chal = ? AND sms_received_at IS NULL AND finished_at >= DATE_SUB(NOW(), INTERVAL " . REATESTER_SMS_CAN_BE_SENT_IN_HOURS . " HOUR)", $sms->suffix);
if (!$session) {
    $sms->status = SMS_STATUS_SESSION_NOT_FOUND;
    $sms->put();
    reply(SMS_REPLY_WRONG_SUFFIX);
}
/************************************************************************************
 Антифрод: ограничение числа номеров телефонов, с которых можно переводить
 деньги на один кошелек
************************************************************************************/
//$sql = sprintf(
//	"SELECT user_phone FROM passwords WHERE wmid = ? AND received_at >= DATE_SUB(NOW(), INTERVAL 1 HOUR) GROUP BY user_phone",
//	mysql_real_escape_string($wmid));
//$result = mysql_query($sql);
//if (!$result) {
//	die('MySQL error: ' . mysql_error());
Exemplo n.º 16
0
 private function authorize_client($client_sock, $input)
 {
     if (Ini::$log_server_events) {
         self::log_debug("TestServer->authorize_client() --- Client authorization started");
     }
     $data = json_decode($input);
     TestSession::change_db($data->workspace_id);
     $session = TestSession::authorized_session($data->workspace_id, $data->session_id, $data->hash);
     if ($session == null) {
         if (Ini::$log_server_events) {
             self::log_debug("TestServer->authorize_client() --- Client authorization failed");
         }
         if (!socket_write($client_sock, json_encode(array("return" => -1)) . chr(0))) {
             if (Ini::$log_server_events) {
                 self::log_debug("TestServer->authorize_client() --- Error: (socket_write) " . socket_last_error() . " - " . socket_strerror(socket_last_error()));
             }
         }
         return false;
     }
     if (!array_key_exists("sid" . $data->workspace_id . "-" . $data->session_id, $this->instances) && $session->status != TestSession::TEST_SESSION_STATUS_SERIALIZED && $session->status != TestSession::TEST_SESSION_STATUS_NEW) {
         if (Ini::$log_server_events) {
             self::log_debug("TestServer->authorize_client() --- Client authorization failed - invalid session");
         }
         if (!socket_write($client_sock, json_encode(array("return" => -1)) . chr(0))) {
             if (Ini::$log_server_events) {
                 self::log_debug("TestServer->authorize_client() --- Error: (socket_write) " . socket_last_error() . " - " . socket_strerror(socket_last_error()));
             }
         }
         return false;
     }
     if (Ini::$log_server_events) {
         self::log_debug("TestServer->authorize_client() --- Client authorization succeeded");
     }
     return true;
 }
Exemplo n.º 17
0
 public static function update_db($simulate = false, $only_recalculate_hash = false, $only_create_db = false)
 {
     require '../Ini.php';
     $ini = new Ini();
     if ($only_create_db) {
         return Ini::create_db_structure();
     }
     if ($only_recalculate_hash) {
         foreach (User::get_all_db() as $db) {
             mysql_select_db($db);
             OModule::calculate_all_xml_hashes();
         }
         return json_encode(array("result" => 0));
     }
     $versions_to_update = array();
     $previous_version = Setting::get_setting("version");
     if ($previous_version == null) {
         $previous_version = Ini::$version;
     }
     $recalculate_hash = false;
     if (Setup::does_patch_apply("4.0.0.beta2", $previous_version)) {
         if ($simulate) {
             array_push($versions_to_update, "4.0.0.beta2");
         } else {
             //RDoc.HTML should be larger
             $sql = "ALTER TABLE `" . Ini::$db_master_name . "`.`RDoc` CHANGE `HTML` `HTML` mediumtext NOT NULL;";
             if (!mysql_query($sql)) {
                 return json_encode(array("result" => 1, "param" => $sql));
             }
             //names should be unique
             $tables = array("Test", "Template", "Table", "QTIAssessmentItem");
             foreach (User::get_all_db() as $db) {
                 foreach ($tables as $table) {
                     $sql = sprintf("SELECT `name` , COUNT(  `name` ) AS `c`\r\n                            FROM  `%s`.`%s` \r\n                            GROUP BY `name` \r\n                            HAVING `c`>1", $db, $table);
                     $z = mysql_query($sql);
                     if (!$z) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                     while ($r = mysql_fetch_array($z)) {
                         $sql = sprintf("UPDATE `%s`.`%s` SET `name`=CONCAT(`name`,'_',`id`) WHERE `name`='%s'", $db, $table, mysql_real_escape_string($r[0]));
                         if (!mysql_query($sql)) {
                             return json_encode(array("result" => 1, "param" => $sql));
                         }
                     }
                     //change object name column to unique
                     $sql = sprintf("ALTER TABLE `%s`.`%s` CHANGE  `name`  `name` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL", $db, $table);
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                     $sql = sprintf("ALTER TABLE  `%s`.`%s` ADD UNIQUE ( `name` )", $db, $table);
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 //add TestSession new columns
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='effect_show'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `effect_show` TEXT NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='effect_hide'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `effect_hide` TEXT NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='effect_show_options'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `effect_show_options` TEXT NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='effect_hide_options'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `effect_hide_options` TEXT NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='loader_HTML'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `loader_HTML` TEXT NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='loader_head'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `loader_head` TEXT NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='loader_effect_show'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `loader_effect_show` TEXT NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='loader_effect_hide'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `loader_effect_hide` TEXT NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='loader_effect_show_options'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `loader_effect_show_options` TEXT NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='loader_effect_hide_options'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `loader_effect_hide_options` TEXT NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='loader_Template_id'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `loader_Template_id` bigint(20) NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='loader_UserWorkspace_id'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `loader_UserWorkspace_id` bigint(20) NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='loader_Template_id'", $db, Test::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) > 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` DROP COLUMN `loader_Template_id`", $db, Test::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
             }
             Setting::set_setting("version", "4.0.0.beta2");
             return json_encode(array("result" => 0, "param" => "4.0.0.beta2"));
         }
     }
     if (Setup::does_patch_apply("4.0.0.beta4", $previous_version)) {
         if ($simulate) {
             array_push($versions_to_update, "4.0.0.beta4");
         } else {
             foreach (User::get_all_db() as $db) {
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='open'", $db, Test::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) > 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` CHANGE `open` `type` TINYINT(1) NOT NULL", $db, Test::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
             }
             Setting::set_setting("version", "4.0.0.beta4");
             return json_encode(array("result" => 0, "param" => "4.0.0.beta4"));
         }
     }
     if (Setup::does_patch_apply("4.0.0.beta9", $previous_version)) {
         if ($simulate) {
             array_push($versions_to_update, "4.0.0.beta9");
         } else {
             foreach (User::get_all_db() as $db) {
                 $sql = sprintf("SHOW COLUMNS FROM `%s`.`%s` WHERE `Field`='resume_declined'", $db, TestSession::get_mysql_table());
                 $z = mysql_query($sql);
                 if (mysql_num_rows($z) == 0) {
                     $sql = sprintf("ALTER TABLE `%s`.`%s` ADD  `resume_declined` tinyint(1) NOT NULL", $db, TestSession::get_mysql_table());
                     if (!mysql_query($sql)) {
                         return json_encode(array("result" => 1, "param" => $sql));
                     }
                 }
             }
             Setting::set_setting("version", "4.0.0.beta9");
             return json_encode(array("result" => 0, "param" => "4.0.0.beta9"));
         }
     }
     if ($simulate) {
         return json_encode(array("versions" => $versions_to_update, "recalculate_hash" => $recalculate_hash, "create_db" => Ini::create_db_structure(true)));
     }
     return json_encode(array("result" => 2));
 }
Exemplo n.º 18
0
<?php

/*
 Concerto Platform - Online Adaptive Testing Platform
 Copyright (C) 2011-2012, The Psychometrics Centre, Cambridge University

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; version 2
 of the License, and not any of the later versions.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
if (!isset($ini)) {
    require_once '../Ini.php';
    $ini = new Ini();
}
TestSession::change_db($_POST['wid']);
$session = TestSession::from_property(array("id" => $_POST['sid'], "hash" => $_POST['hash']), false);
if ($session != null) {
    $session->log_error($_POST['message'], TestSessionLog::TEST_SESSION_LOG_TYPE_JS);
}
Exemplo n.º 19
0
<?php

include '../lib/common.inc.php';
$title = "Недавние тесты";
$recent_limit = 100;
$finished_sessions = TestSession::query("WHERE `finished_at` IS NOT NULL ORDER BY `started_at` DESC LIMIT {$recent_limit}");
$unfinished_sessions = TestSession::query("WHERE `finished_at` IS NULL ORDER BY `started_at` DESC LIMIT {$recent_limit}");
$sms_sessions = TestSession::query("WHERE `sms_received_at` IS NOT NULL ORDER BY `started_at` DESC LIMIT {$recent_limit}");
render('recent.haml', array('unfinished_sessions' => $unfinished_sessions, 'finished_sessions' => $finished_sessions, 'sms_sessions' => $sms_sessions, 'tab' => 'recent', 'recent_limit' => $recent_limit));
Exemplo n.º 20
0
 public function get_Test()
 {
     TestSession::change_db($this->UserWorkspace_id);
     $session = $this->get_TestSession();
     if ($session == null) {
         return null;
     }
     return Test::from_mysql_id($session->Test_id);
 }
Exemplo n.º 21
0
 public function executeImportRestApi(sfWebRequest $request)
 {
     $qa_generic = sfConfig::get("app_table_qa_generic");
     $qa_core = sfConfig::get("app_table_qa_core");
     // Retrieve $_GET (main parameters)
     $get_params['auth_token'] = $request->getGetParameter("auth_token");
     $get_params['release_version'] = $request->getGetParameter("release_version");
     $get_params['target'] = $request->getGetParameter("target");
     $get_params['testtype'] = $request->getGetParameter("testtype");
     $get_params['testset'] = $request->getGetParameter("testset");
     $get_params['hwproduct'] = $request->getGetParameter("hwproduct");
     $get_params['product'] = $request->getGetParameter("product");
     $get_params['hardware'] = $request->getGetParameter("hardware");
     $get_params['image'] = $request->getGetParameter("image");
     $get_params['build_id'] = $request->getGetParameter("build_id");
     // Retrieve $_GET (additional parameters)
     $get_params['tested_at'] = $request->getGetParameter("tested_at");
     $get_params['report_title'] = $request->getGetParameter("title");
     $get_params['objective_txt'] = $request->getGetParameter("objective_txt");
     $get_params['build_txt'] = $request->getGetParameter("build_txt");
     $get_params['environment_txt'] = $request->getGetParameter("environment_txt");
     $get_params['qa_summary_txt'] = $request->getGetParameter("qa_summary_txt");
     $get_params['issue_summary_txt'] = $request->getGetParameter("issue_summary_txt");
     $get_params['status'] = $request->getGetParameter("status");
     // Retrieve $_GET (hwproduct additional fields)
     $get_params['te_desc'] = $request->getGetParameter("te_desc");
     $get_params['te_cpu'] = $request->getGetParameter("te_cpu");
     $get_params['te_board'] = $request->getGetParameter("te_board");
     $get_params['te_gpu'] = $request->getGetParameter("te_gpu");
     $get_params['te_hw'] = $request->getGetParameter("te_hw");
     // Retrieve $_GET (image additional fields)
     $get_params['img_desc'] = $request->getGetParameter("img_desc");
     $get_params['img_os'] = $request->getGetParameter("img_os");
     $get_params['img_dist'] = $request->getGetParameter("img_dist");
     $get_params['img_vers'] = $request->getGetParameter("img_vers");
     $get_params['img_kernel'] = $request->getGetParameter("img_kernel");
     $get_params['img_arch'] = $request->getGetParameter("img_arch");
     $get_params['img_other'] = $request->getGetParameter("img_other");
     $get_params['img_bin'] = $request->getGetParameter("img_bin");
     $get_params['img_src'] = $request->getGetParameter("img_src");
     // Old parameters support about test_environment (testtype)
     if (!isset($get_params['testtype'])) {
         $get_params['testtype'] = $get_params['testset'];
     }
     // Old parameters support about image (hwproduct)
     if (!isset($get_params['hwproduct'])) {
         if (!isset($get_params['product'])) {
             $get_params['hwproduct'] = $get_params['hardware'];
         } else {
             $get_params['hwproduct'] = $get_params['product'];
         }
     }
     // Check if auth_token parameter is empty
     if (empty($get_params['auth_token'])) {
         echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing auth_token parameter\"}}\n";
         exit;
     }
     // Check if release_version parameter is empty
     if (empty($get_params['release_version'])) {
         echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing release_version parameter\"}}\n";
         exit;
     }
     // Check if target parameter is empty
     if (empty($get_params['target'])) {
         echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing target parameter\"}}\n";
         exit;
     }
     // Check if hwproduct parameter is empty
     if (empty($get_params['hwproduct'])) {
         echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing hwproduct parameter\"}}\n";
         exit;
     }
     // Check if image parameter is empty
     if (empty($get_params['image'])) {
         $get_params['image'] = "Empty_image";
     }
     // Retrieve project_id relying on project name (if it doesn't exist, return an error)
     $query = "SELECT proj.id AS project_id\n\t\t\t\t\tFROM " . $qa_generic . ".project proj\n\t\t\t\t\tWHERE proj.name = '" . $get_params['release_version'] . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["project_id"])) {
         echo "{\"ok\":\"0\",\"errors\":{\"release_version\":\"Incorrect release_version '" . $get_params['release_version'] . "'\"}}\n";
         exit;
     }
     $project_id = $result["project_id"];
     // Retrieve project_group_id relying on project_group_name (if it doesn't exist, return an error)
     $query = "SELECT pg.id AS project_group_id\n\t\t\t\t\tFROM " . $qa_core . ".sf_guard_group pg\n\t\t\t\t\tWHERE pg.name = '" . sfConfig::get("app_project_group") . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["project_group_id"])) {
         echo "{\"ok\":\"0\",\"errors\":{\"project_group_name\":\"Incorrect project_group_name '" . sfConfig::get("app_project_group") . "'\"}}\n";
         exit;
     }
     $project_group_id = $result["project_group_id"];
     // Retrieve product_id relying on product formfactor (if it doesn't exist, return an error)
     $query = "SELECT pt.id AS product_id\n\t\t\t\t\tFROM " . $qa_core . ".product_type pt\n\t\t\t\t\tWHERE pt.name = '" . $get_params['target'] . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["product_id"])) {
         echo "{\"ok\":\"0\",\"errors\":{\"target\":\"Incorrect target '" . $get_params['target'] . "'\"}}\n";
         exit;
     }
     $product_id = $result["product_id"];
     // Retrieve project_to_product_id, relying on project_id, project_group_id, and product_id
     $query = "SELECT ptp.id AS ptp_id\n\t\t\t\t\tFROM " . $qa_generic . ".project_to_product ptp\n\t\t\t\t\tWHERE ptp.project_id = " . $project_id . "\n\t\t\t\t\t\tAND ptp.project_group_id = " . $project_group_id . "\n\t\t\t\t\t\tAND ptp.product_id = " . $product_id;
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["ptp_id"])) {
         echo "{\"ok\":\"0\",\"errors\":{\"project_to_product\":\"Cannot find project_to_product_id\"}}\n";
         exit;
     }
     $project_to_product_id = $result["ptp_id"];
     // Retrieve user_id, relying on auth_token
     $query = "SELECT up.user_id\n\t\t\t\t\tFROM " . $qa_core . ".sf_guard_user_profile up\n\t\t\t\t\tWHERE up.token = '" . $get_params['auth_token'] . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["user_id"])) {
         echo "{\"ok\":\"0\",\"errors\":{\"auth_token\":\"Authorized token is not valid\"}}\n";
         exit;
     }
     $user_id = $result["user_id"];
     // Customize database connection to begin a transactionnal query
     $conn = Doctrine_Manager::getInstance()->getConnection("qa_generic");
     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, FALSE);
     $conn->beginTransaction();
     // If test_environment_name exists, retrieve id, else, create new entry and retrieve id
     $query = "SELECT te.id AS test_environment_id\n\t\t\t\t\tFROM " . $qa_generic . ".test_environment te\n\t\t\t\t\tWHERE te.name = '" . $get_params['hwproduct'] . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["test_environment_id"])) {
         // Check if creation of a new entry is allowed
         if (sfConfig::get("app_rest_configuration_creation", false) == false) {
             $conn->rollback();
             $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
             echo "{\"ok\":\"0\",\"errors\":{\"test_environment\":\"Creation of new test environment is forbidden\"}}\n";
             exit;
         } else {
             // Add new environment
             $environment = new TestEnvironment();
             $environment->setName($get_params['hwproduct']);
             $environment->setNameSlug(MiscUtils::slugify($get_params['hwproduct']));
             // Add hwproduct additional fields if given as parameters
             if (isset($get_params['te_desc'])) {
                 $environment->setDescription($get_params['te_desc']);
             }
             if (isset($get_params['te_cpu'])) {
                 $environment->setCpu($get_params['te_cpu']);
             }
             if (isset($get_params['te_board'])) {
                 $environment->setBoard($get_params['te_board']);
             }
             if (isset($get_params['te_gpu'])) {
                 $environment->setGpu($get_params['te_gpu']);
             }
             if (isset($get_params['te_hw'])) {
                 $environment->setOtherHardware($get_params['te_hw']);
             }
             // Save new environment
             $environment->save($conn);
             $environmentId = $environment->getId();
         }
     } else {
         $environmentId = $result["test_environment_id"];
     }
     // If image_name exists, retrieve id, else, create new entry and retrieve id
     $query = "SELECT i.id AS image_id\n\t\t\t\t\tFROM " . $qa_generic . ".image i\n\t\t\t\t\tWHERE i.name = '" . $get_params['image'] . "'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["image_id"])) {
         // Check if creation of a new entry is allowed
         if (sfConfig::get("app_rest_configuration_creation", false) == false) {
             $conn->rollback();
             $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
             echo "{\"ok\":\"0\",\"errors\":{\"image\":\"Creation of new image is forbidden\"}}\n";
             exit;
         } else {
             // Add new image
             $image = new Image();
             $image->setName($get_params['image']);
             $image->setNameSlug(MiscUtils::slugify($get_params['image']));
             // Add image additional fields if given as parameters
             if (isset($get_params['img_desc'])) {
                 $image->setDescription($get_params['img_desc']);
             }
             if (isset($get_params['img_os'])) {
                 $image->setOs($get_params['img_os']);
             }
             if (isset($get_params['img_dist'])) {
                 $image->setDistribution($get_params['img_dist']);
             }
             if (isset($get_params['img_vers'])) {
                 $image->setVersion($get_params['img_vers']);
             }
             if (isset($get_params['img_kernel'])) {
                 $image->setKernel($get_params['img_kernel']);
             }
             if (isset($get_params['img_arch'])) {
                 $image->setArchitecture($get_params['img_arch']);
             }
             if (isset($get_params['img_other'])) {
                 $image->setOtherFw($get_params['img_other']);
             }
             if (isset($get_params['img_bin'])) {
                 $image->setBinaryLink($get_params['img_bin']);
             }
             if (isset($get_params['img_src'])) {
                 $image->setSourceLink($get_params['img_src']);
             }
             // Save new image
             $image->save($conn);
             $imageId = $image->getId();
         }
     } else {
         $imageId = $result["image_id"];
     }
     // If configuration exists, retrieve id, else, create new entry and retrieve id
     $query = "SELECT c.id AS configuration_id\n\t\t\t\t\tFROM " . $qa_generic . ".configuration c\n\t\t\t\t\tWHERE c.project_to_product_id = " . $project_to_product_id . "\n\t\t\t\t\t\tAND c.test_environment_id = " . $environmentId . "\n\t\t\t\t\t\tAND c.image_id = " . $imageId;
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     if (empty($result["configuration_id"])) {
         $configuration = new Configuration();
         $configuration->setProjectToProductId($project_to_product_id);
         $configuration->setTestEnvironmentId($environmentId);
         $configuration->setImageId($imageId);
         $configuration->save($conn);
         $configurationId = $configuration->getId();
     } else {
         $configurationId = $result["configuration_id"];
     }
     $date_now = date("Y-m-d H:i:s");
     $date_now_wo_sec = date("Y-m-d H:i");
     $testSession = new TestSession();
     $testSession->setName($get_params['target'] . " " . $get_params['testtype'] . " " . $get_params['hwproduct'] . " " . $date_now_wo_sec . " " . $get_params['build_id']);
     $testSession->setUserId($user_id);
     $testSession->setCreatedAt($date_now);
     $testSession->setUpdatedAt($date_now);
     $testSession->setStatus(2);
     $testSession->setPublished(1);
     $testSession->setConfigurationId($configurationId);
     // Fill in the build_id if it is given
     if (!empty($get_params['build_id'])) {
         $testSession->setBuildId($get_params['build_id']);
         $testSession->setBuildSlug(MiscUtils::slugify($get_params['build_id']));
     }
     // Fill in the testset if it is given
     if (!empty($get_params['testtype'])) {
         $testSession->setTestset($get_params['testtype']);
         $testSession->setTestsetSlug(MiscUtils::slugify($get_params['testtype']));
     }
     if (isset($get_params['report_title'])) {
         $testSession->setName($get_params['report_title']);
     }
     if (isset($get_params['objective_txt'])) {
         $testSession->setTestObjective($get_params['objective_txt']);
     }
     if (isset($get_params['environment_txt'])) {
         $testSession->setNotes($get_params['environment_txt']);
     }
     if (isset($get_params['qa_summary_txt'])) {
         $testSession->setQaSummary($get_params['qa_summary_txt']);
     }
     if (isset($get_params['issue_summary_txt'])) {
         $testSession->setIssueSummary($get_params['issue_summary_txt']);
     }
     if (isset($get_params['status'])) {
         $testSession->setStatus($get_params['status']);
     }
     $testSession->save($conn);
     $testSessionId = $testSession->getId();
     // Retrieve table_name_test_session_id from table_name
     $query = "SELECT tn.id AS table_name_id\n\t\t\t\t\tFROM " . $qa_generic . ".table_name tn\n\t\t\t\t\tWHERE tn.name = 'test_session'";
     $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     $tableNameTestSessionId = $result["table_name_id"];
     // Concatenate directory path
     $dir_path = sfConfig::get('sf_upload_dir') . "/testsession_" . $testSessionId;
     // Get all files sent
     $files = $request->getFiles();
     // Check if there is any report file to import
     if (empty($files)) {
         $conn->rollback();
         $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
         echo "{\"ok\":\"0\",\"errors\":\"Missing report file\"}\n";
         exit;
     }
     // Import each report file and register attachment files
     $report_file_found = false;
     foreach ($files as $key => $file) {
         $reportType = false;
         $fileName = $file['name'];
         $fileSize = $file['size'];
         $fileType = $file['type'];
         $fileError = $file['error'];
         $fileChecksum = sha1_file($file["tmp_name"]);
         // Check file error and file size
         if (!$fileError and $fileSize <= sfConfig::get('app_max_file_size', '10000000')) {
             if (!is_dir($dir_path)) {
                 mkdir($dir_path, 0777, true);
             }
             $dest_path = $dir_path . "/" . $fileName;
             // Move file to uploads directory
             move_uploaded_file($file['tmp_name'], $dest_path);
             $web_path = "/uploads" . "/testsession_" . $testSessionId . "/" . $fileName;
             $fileAttachment = new FileAttachment();
             $fileAttachment->setName($fileName);
             $fileAttachment->setUserId($user_id);
             $fileAttachment->setUploadedAt(date("Y-m-d H:i:s"));
             $fileAttachment->setFilename($fileName);
             $fileAttachment->setFileSize($fileSize);
             $fileAttachment->setFileMimeType($fileType);
             $fileAttachment->setLink($web_path);
             $fileAttachment->setChecksum($fileChecksum);
             $fileAttachment->setTableNameId($tableNameTestSessionId);
             $fileAttachment->setTableEntryId($testSessionId);
             if ((preg_match("#\\.xml\$#i", $fileName) | preg_match("#\\.csv\$#i", $fileName)) & !preg_match("#attachment.?[0-9]*#i", $key)) {
                 $report_file_found = true;
                 $reportType = true;
                 $fileAttachment->setCategory(1);
             } else {
                 if (preg_match("#attachment.?[0-9]*#i", $key)) {
                     $fileAttachment->setCategory(2);
                 } else {
                     $conn->rollback();
                     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                     echo "{\"ok\":\"0\",\"errors\":\"Only upload files with the extension .xml or .csv\"}\n";
                     exit;
                 }
             }
             $fileAttachment->save($conn);
             // If it is an XML or CSV file, parse it and fill qa_generic database
             if ($reportType) {
                 if ($err_code = Import::file($dest_path, $testSessionId, $configurationId, $conn)) {
                     $error_message = Import::getImportErrorMessage($err_code);
                     MiscUtils::deleteDir($dir_path);
                     $conn->rollback();
                     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                     echo "{\"ok\":\"0\",\"errors\":\"File " . $fileName . " is not valid = " . $error_message . "\"}\n";
                     exit;
                 }
             }
         } else {
             MiscUtils::deleteDir($dir_path);
             $conn->rollback();
             $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
             echo "{\"ok\":\"0\",\"errors\":\"File " . $fileName . " exceed maximum size\"}\n";
             exit;
         }
     }
     // If only attachment files have been found, cancel the new test session
     if (!$report_file_found) {
         $conn->rollback();
         $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
         echo "{\"ok\":\"0\",\"errors\":\"Missing report file\"}\n";
         exit;
     }
     $conn->commit();
     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
     // Retrieve project name_slug, product name_slug, test environment name_slug and image name_slug
     $query = "SELECT i.name_slug image_name_slug, te.name_slug test_environment_name_slug, p.name_slug project_name_slug, pt.name_slug product_name_slug\n\t\t\t\t\tFROM " . $qa_generic . ".test_session ts\n\t\t\t\t\tJOIN " . $qa_generic . ".configuration c ON c.id = ts.configuration_id\n\t\t\t\t\tJOIN " . $qa_generic . ".image i ON i.id = c.image_id\n\t\t\t\t\tJOIN " . $qa_generic . ".test_environment te ON te.id = c.test_environment_id\n\t\t\t\t\tJOIN " . $qa_generic . ".project_to_product ptp ON ptp.id = c.project_to_product_id\n\t\t\t\t\tJOIN " . $qa_generic . ".project p ON p.id = ptp.project_id\n\t\t\t\t\tJOIN " . $qa_core . ".product_type pt ON pt.id = ptp.product_id\n\t\t\t\t\tWHERE ts.id = " . $testSessionId;
     $configInfo = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
     $projectNameSlug = $configInfo['project_name_slug'];
     $productNameSlug = $configInfo['product_name_slug'];
     $testEnvironmentNameSlug = $configInfo['test_environment_name_slug'];
     $imageNameSlug = $configInfo['image_name_slug'];
     // Return datas to CATS
     $url_to_return = $request->getUriPrefix() . $this->generateUrl("test_session", array('project' => $projectNameSlug, 'product' => $productNameSlug, 'environment' => $testEnvironmentNameSlug, 'image' => $imageNameSlug, 'id' => $testSessionId));
     echo "{\"ok\":\"1\",\"url\":\"" . $url_to_return . "\"}\n";
     // Return is done (with echo) so make sure nothing else will be sent
     exit;
 }
Exemplo n.º 22
0
 private function get_client($client_sock, &$input)
 {
     $data = json_decode($input);
     $key = "sid" . $data->session_id;
     if (!array_key_exists($key, $this->clients)) {
         $session = TestSession::from_mysql_id($data->session_id);
         if ($session->serialized == 1) {
             include Ini::$path_internal . 'SETTINGS.php';
             $code = "\r\n                options(encoding='UTF-8')\r\n                options(error=quote(stop(geterrmessage())))\r\n                library(session)\r\n                restore.session('" . $session->get_RSession_file_path() . "')\r\n\r\n                CONCERTO_DB_HOST <- '" . $db_host . "'\r\n                CONCERTO_DB_PORT <- as.numeric(" . ($db_port != "" ? $db_port : "3306") . ")\r\n                CONCERTO_DB_LOGIN <- '" . $db_user . "'\r\n                CONCERTO_DB_PASSWORD <- '" . $db_password . "'\r\n\r\n                CONCERTO_DRIVER <- dbDriver('MySQL')\r\n                for(CONCERTO_DB_CONNECTION in dbListConnections(CONCERTO_DRIVER)) { dbDisconnect(CONCERTO_DB_CONNECTION) }\r\n                CONCERTO_DB_CONNECTION <- dbConnect(CONCERTO_DRIVER, user = CONCERTO_DB_LOGIN, password = CONCERTO_DB_PASSWORD, dbname = CONCERTO_DB_NAME, host = CONCERTO_DB_HOST, port = CONCERTO_DB_PORT, client.flag=CLIENT_MULTI_STATEMENTS)\r\n                dbSendQuery(CONCERTO_DB_CONNECTION,statement = \"SET NAMES 'utf8';\")\r\n                dbSendQuery(CONCERTO_DB_CONNECTION,statement = \"SET time_zone='" . Ini::$mysql_timezone . "';\")\r\n\r\n                rm(CONCERTO_DB_HOST)\r\n                rm(CONCERTO_DB_PORT)\r\n                rm(CONCERTO_DB_LOGIN)\r\n                rm(CONCERTO_DB_PASSWORD)\r\n                ";
             $session->serialized = 0;
             $session->mysql_save();
             $data->code = $code . $data->code;
             $input = json_encode($data);
         }
         $this->clients[$key] = array();
         $this->clients[$key]["sock"] = $client_sock;
         if (self::$debug) {
             self::log_debug("TestServer->get_client() --- Client '{$key}' added");
         }
     } else {
         if (is_resource($this->clients[$key]["sock"])) {
             //@socket_shutdown($this->clients[$key]["sock"]);
             socket_close($this->clients[$key]["sock"]);
             $this->clients[$key]["sock"] = $client_sock;
         }
         if (self::$debug) {
             self::log_debug("TestServer->get_client() --- Client '{$key}' loaded");
         }
     }
     return $this->clients[$key];
 }
Exemplo n.º 23
0
 public function log_error($message = null, $type = TestSessionLog::TEST_SESSION_LOG_TYPE_R)
 {
     if ($message == null) {
         $message = $this->error_output;
     }
     TestSession::create_session_log($type, $this->UserWorkspace_id, $this->id, $this->Test_id, $this->hash, $this->Template_id, $this->Template_UserWorkspace_id, $this->status, $message, $_SERVER['REMOTE_ADDR'], $_SERVER["HTTP_USER_AGENT"]);
 }
Exemplo n.º 24
0
 public function serialize()
 {
     if (TestServer::$debug) {
         TestServer::log_debug("TestInstance->serialize() --- Serializing #" . $this->session_id);
     }
     $session = TestSession::from_mysql_id($this->session_id);
     $this->is_serializing = true;
     $this->send(sprintf("\n            save.session('%s')\n            ", $session->get_RSession_file_path()));
 }