本文整理汇总了PHP中Import::file方法的典型用法代码示例。如果您正苦于以下问题:PHP Import::file方法的具体用法?PHP Import::file怎么用?PHP Import::file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Import
的用法示例。
在下文中一共展示了Import::file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeImportRestApiMerge
public function executeImportRestApiMerge(sfWebRequest $request)
{
$qa_generic = sfConfig::get("app_table_qa_generic");
$qa_core = sfConfig::get("app_table_qa_core");
// Retrieve test session id to update
$testSessionId = $request->getParameter("id");
// Retrieve $_GET
$get_params['auth_token'] = $request->getGetParameter("auth_token");
// Check if id parameter is empty
if (empty($testSessionId)) {
echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing test session id parameter\"}}\n";
exit;
}
// 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 authorized token exists, and retrieve user_id
$sfGuardUserProfileObject = Doctrine_Core::getTable("sfGuardUserProfile")->findOneByToken($get_params['auth_token']);
if (empty($sfGuardUserProfileObject)) {
echo "{\"ok\":\"0\",\"errors\":{\"auth_token\":\"Authorized token is not valid\"}}\n";
exit;
}
$user_id = $sfGuardUserProfileObject->getUserId();
// Customize database connection to begin a transactionnal query
$conn = Doctrine_Manager::getInstance()->getConnection("qa_generic");
$conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, FALSE);
$conn->beginTransaction();
// Update test_session table
$testSession = Doctrine_Core::getTable("TestSession")->findOneById($testSessionId);
$testSession->setUpdatedAt(date("Y-m-d H:i:s"));
$testSession->save($conn);
// Retrieve table_name_test_session_id from table_name
$tableName = Doctrine_Core::getTable("TableName")->findOneByName("test_session");
$tableNameTestSessionId = $tableName->getId();
// Get file attachments id into an array
$fileAttachmentIdList = array();
$fileAttachments = Doctrine_Query::create()->select('*')->from('FileAttachment')->where('table_entry_id = ?', $testSessionId)->andWhere('table_name_id = ?', $tableNameTestSessionId)->execute();
foreach ($fileAttachments as $fileAttachment) {
$fileAttachmentIdList[] = $fileAttachment->getId();
}
// Concatenate directory path
$dir_path = sfConfig::get('sf_upload_dir') . "/testsession_" . $testSessionId;
$fileAttachmentResultIds = array();
$similarFileFound = false;
// 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"]);
$fileAttachmentResult = Doctrine_Query::create()->select('*')->from('FileAttachment')->where('table_entry_id = ?', $testSessionId)->andWhere('table_name_id = ?', $tableNameTestSessionId)->andWhere('checksum = ?', $fileChecksum)->execute();
if (!empty($fileAttachmentResult[0])) {
$fileAttachmentResultIds[] = $fileAttachmentResult[0]->getId();
$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($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;
//.........这里部分代码省略.........
示例2: processEdit
/**
* Process the form to edit an existing test session.
*
* @param sfWebRequest $request
* @param SessionForm $form
*/
protected function processEdit(sfWebRequest $request, SessionForm $form)
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid()) {
$qa_generic = sfConfig::get("app_table_qa_generic");
// 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"];
// Get test environment and image names
$environmentForm = $form->getValue("environmentForm");
$imageForm = $form->getValue("imageForm");
// 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();
}
// Edit the session into DB
$testSession = Doctrine_Core::getTable("TestSession")->find($values["id"]);
$testSession->setId($values["id"]);
$testSession->setBuildId($values["build_id"]);
$testSession->setTestset($values["testset"]);
$testSession->setName($values["name"]);
$testSession->setTestObjective($values["test_objective"]);
$testSession->setQaSummary($values["qa_summary"]);
$testSession->setUserId($values["user_id"]);
//.........这里部分代码省略.........