当前位置: 首页>>代码示例>>PHP>>正文


PHP Import::getImportErrorMessage方法代码示例

本文整理汇总了PHP中Import::getImportErrorMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Import::getImportErrorMessage方法的具体用法?PHP Import::getImportErrorMessage怎么用?PHP Import::getImportErrorMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Import的用法示例。


在下文中一共展示了Import::getImportErrorMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: executeImportRestApiMerge


//.........这里部分代码省略.........
         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;
             $idx = 0;
             while (is_file($dest_path)) {
                 $idx++;
                 $dest_path = $dir_path . "/" . "(" . $idx . ")" . $fileName;
             }
             // Move file to uploads directory
             move_uploaded_file($file['tmp_name'], $dest_path);
             if ($idx == 0) {
                 $web_path = "/uploads" . "/testsession_" . $testSessionId . "/" . $fileName;
             } else {
                 $web_path = "/uploads" . "/testsession_" . $testSessionId . "/" . "(" . $idx . ")" . $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, true)) {
                     // Delete new files
                     $fileAttachments = Doctrine_Query::create()->select('*')->from('FileAttachment')->where('table_entry_id = ?', $testSessionId)->andWhere('table_name_id = ?', $tableNameTestSessionId)->andWhereNotIn('id', $fileAttachmentIdList)->execute();
                     foreach ($fileAttachments as $fileAttachment) {
                         unlink(sfConfig::get('sf_web_dir') . $fileAttachment->getLink());
                     }
                     $error_message = Import::getImportErrorMessage($err_code);
                     $conn->rollback();
                     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                     echo "{\"ok\":\"0\",\"errors\":\"File " . $fileName . " is not valid = " . $error_message . "\"}\n";
                     exit;
                 }
             }
         } else {
             // Delete new files
             $fileAttachments = Doctrine_Query::create()->select('*')->from('FileAttachment')->where('table_entry_id = ?', $testSessionId)->andWhere('table_name_id = ?', $tableNameTestSessionId)->andWhereNotIn('id', $fileAttachmentIdList)->execute();
             foreach ($fileAttachments as $fileAttachment) {
                 unlink(sfConfig::get('sf_web_dir') . $fileAttachment->getLink());
             }
             $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;
     }
     if ($similarFileFound) {
         // Delete similar files and attachment entries
         $fileAttachments = Doctrine_Query::create()->select('*')->from('FileAttachment')->where('table_entry_id = ?', $testSessionId)->andWhere('table_name_id = ?', $tableNameTestSessionId)->andWhereIn('id', $fileAttachmentResultIds)->execute();
         foreach ($fileAttachments as $fileAttachment) {
             unlink(sfConfig::get('sf_web_dir') . $fileAttachment->getLink());
             $fileAttachment->delete($conn);
         }
     }
     $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;
 }
开发者ID:alex1818,项目名称:TestReportCenter,代码行数:101,代码来源:actions.class.php

示例2: processEdit


//.........这里部分代码省略.........
                 $fileSize = $file['size'];
                 $fileType = $file['type'];
                 $fileError = $file['error'];
                 $fileChecksum = sha1_file($file["tmp_name"]);
                 $query = "SELECT fa.id\n\t\t\t\t\t\t\tFROM " . $qa_generic . ".file_attachment fa\n\t\t\t\t\t\t\tWHERE fa.table_entry_id = " . $testSessionId . "\n\t\t\t\t\t\t\t\tAND fa.table_name_id = " . $tableNameTestSessionId . "\n\t\t\t\t\t\t\t\tAND fa.checksum = '" . $fileChecksum . "'";
                 $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC);
                 if (!empty($result["id"])) {
                     $fileAttachmentResultIds[] = $result["id"];
                     $similarFileFound = true;
                 }
                 // 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;
                     $idx = 0;
                     while (is_file($dest_path)) {
                         $idx++;
                         $dest_path = $dir_path . "/" . "(" . $idx . ")" . $fileName;
                     }
                     // Move file to uploads directory
                     move_uploaded_file($file['tmp_name'], $dest_path);
                     if ($idx == 0) {
                         $web_path = "/uploads" . "/testsession_" . $testSessionId . "/" . $fileName;
                     } else {
                         $web_path = "/uploads" . "/testsession_" . $testSessionId . "/" . "(" . $idx . ")" . $fileName;
                     }
                     $fileAttachment = new FileAttachment();
                     $fileAttachment->setName($fileName);
                     $fileAttachment->setUserId($this->getUser()->getGuardUser()->getId());
                     $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)) {
                         $reportType = true;
                         $fileAttachment->setCategory(1);
                     } else {
                         $fileAttachment->setCategory(2);
                     }
                     $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, true)) {
                             // Delete new files
                             $query = "SELECT fa.link\n\t\t\t\t\t\t\t\t\t\tFROM " . $qa_generic . ".file_attachment fa\n\t\t\t\t\t\t\t\t\t\tWHERE fa.table_entry_id = " . $testSessionId . "\n\t\t\t\t\t\t\t\t\t\t\tAND fa.table_name_id = " . $tableNameTestSessionId . "\n\t\t\t\t\t\t\t\t\t\t\tAND fa.id NOT IN (" . $fileAttachmentIdStringList . ")";
                             $results = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetchAll(PDO::FETCH_ASSOC);
                             foreach ($results as $result) {
                                 unlink(sfConfig::get('sf_web_dir') . $result["link"]);
                             }
                             $error_message = Import::getImportErrorMessage($err_code);
                             $conn->rollback();
                             $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                             $this->getUser()->setFlash("error", "Invalid file content on " . $fileName . " : " . $error_message);
                             $this->redirect("edit_report", array("project" => $projectSlug, "product" => $productSlug, "environment" => $environment["name_slug"], "image" => $image["name_slug"], "id" => $testSessionId));
                         }
                     }
                 } else {
                     // Delete new files
                     $query = "SELECT fa.link\n\t\t\t\t\t\t\t\tFROM " . $qa_generic . ".file_attachment fa\n\t\t\t\t\t\t\t\tWHERE fa.table_entry_id = " . $testSessionId . "\n\t\t\t\t\t\t\t\t\tAND fa.table_name_id = " . $tableNameTestSessionId . "\n\t\t\t\t\t\t\t\t\tAND fa.id NOT IN (" . $fileAttachmentIdStringList . ")";
                     $results = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetchAll(PDO::FETCH_ASSOC);
                     foreach ($results as $result) {
                         unlink(sfConfig::get('sf_web_dir') . $result["link"]);
                     }
                     $conn->rollback();
                     $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
                     $this->getUser()->setFlash("error", "File size limit reached");
                     $this->redirect("edit_report", array("project" => $projectSlug, "product" => $productSlug, "environment" => $environment["name_slug"], "image" => $image["name_slug"], "id" => $testSessionId));
                 }
             }
         }
         if ($similarFileFound) {
             $fileAttachmentStringResultIds = implode(",", $fileAttachmentResultIds);
             // Delete similar files and attachment entries
             $query = "SELECT fa.id, fa.link\n\t\t\t\t\t\tFROM " . $qa_generic . ".file_attachment fa\n\t\t\t\t\t\tWHERE fa.table_entry_id = " . $testSessionId . "\n\t\t\t\t\t\t\tAND fa.table_name_id = " . $tableNameTestSessionId . "\n\t\t\t\t\t\t\tAND fa.id IN (" . $fileAttachmentStringResultIds . ")";
             $results = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetchAll(PDO::FETCH_ASSOC);
             foreach ($results as $result) {
                 unlink(sfConfig::get('sf_web_dir') . $result["link"]);
                 Doctrine_Core::getTable("FileAttachment")->deleteFileAttachmentById($result["id"], $conn);
             }
         }
         $conn->commit();
         $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE);
         // 			// Clear cache for actions related to this test session
         // 			$cacheManager = $this->getContext()->getViewCacheManager();
         // 			$cacheManager->remove("reports/session?project=".$projectSlug."&product=".$productSlug."&environment=".$environment["name_slug"]."&image=".$image["name_slug"]."?id=".$testSession["id"]);
         // Set flash for user and redirect to session display
         $this->getUser()->setFlash("notice", "Test session was updated successfully");
         if (!empty($testSession["build_slug"])) {
             $this->redirect("build_session", array("project" => $projectSlug, "product" => $productSlug, "build" => $testSession["build_slug"], "environment" => $environment["name_slug"], "image" => $image["name_slug"], "id" => $request->getParameter("id")));
         } else {
             $this->redirect("test_session", array("project" => $projectSlug, "product" => $productSlug, "environment" => $environment["name_slug"], "image" => $image["name_slug"], "id" => $request->getParameter("id")));
         }
     }
 }
开发者ID:alex1818,项目名称:TestReportCenter,代码行数:101,代码来源:actions.class.php


注:本文中的Import::getImportErrorMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。