Ejemplo n.º 1
0
 public static function AddDirectory($zip, $source, $prefix, $excluded)
 {
     if (!is_dir($source)) {
         return;
     }
     if ($handle = opendir($source)) {
         while (false !== ($entry = readdir($handle))) {
             if ($entry == '.' || $entry == '..') {
                 continue;
             }
             $sourcePath = "{$source}/{$entry}";
             $targetPath = $prefix == '' ? $entry : "{$prefix}/{$entry}";
             if (in_array($targetPath, $excluded)) {
                 continue;
             }
             if (is_dir($sourcePath)) {
                 $zip->AddEmptyDir($targetPath);
                 ZipHandler::AddDirectory($zip, $sourcePath, $targetPath, $excluded);
             } else {
                 $zip->addFile($sourcePath, $targetPath);
             }
         }
         closedir($handle);
     }
 }
Ejemplo n.º 2
0
 /**
  * Entry point for zip validation
  * Determines the type of problem we are deploying
  *
  * @return boolean
  * @throws InvalidParameterException
  */
 private function validateZip()
 {
     $this->log->info('Validating zip...');
     if (!array_key_exists('problem_contents', $_FILES)) {
         $this->log->error('\\$_FILES global does not contain problem_contents.');
         throw new InvalidParameterException('parameterEmpty', 'problem_contents');
     }
     if (isset($_FILES['problem_contents']) && !FileHandler::GetFileUploader()->IsUploadedFile($_FILES['problem_contents']['tmp_name'])) {
         $this->log->error("GetFileUploader()->IsUploadedFile() check failed for \$_FILES['problem_contents']['tmp_name'].");
         throw new InvalidParameterException('parameterEmpty', 'problem_contents');
     }
     $this->filesToUnzip = array();
     $this->imageHashes = array();
     $this->casesFiles = array();
     $this->zipPath = $_FILES['problem_contents']['tmp_name'];
     $this->log->info("Opening {$this->zipPath}...");
     $zip = new ZipArchive();
     $resource = $zip->open($this->zipPath);
     $size = 0;
     if ($resource !== true) {
         $this->log->error('Unable to open zip file: ' . ZipHandler::ErrorMessage($resource));
         throw new InvalidParameterException('problemDeployerCorruptZip');
     }
     // Get list of files
     for ($i = 0; $i < $zip->numFiles; $i++) {
         $this->log->info("Found inside zip: '" . $zip->getNameIndex($i) . "'");
         $zipFilesArray[] = $zip->getNameIndex($i);
         // Sum up the size
         $statI = $zip->statIndex($i);
         $size += $statI['size'];
         // If the file is THE validator for custom outputs...
         if (stripos($zip->getNameIndex($i), 'validator.') === 0) {
             $this->hasValidator = true;
             $this->filesToUnzip[] = $zip->getNameIndex($i);
             $this->log->info('Validator found: ' . $zip->getNameIndex($i));
         }
         // Interactive problems.
         if (stripos($zip->getNameIndex($i), 'interactive/') === 0) {
             $this->filesToUnzip[] = $zip->getNameIndex($i);
             $this->isInteractive = true;
             if (ProblemDeployer::endsWith($zip->getNameIndex($i), '.idl', true)) {
                 $this->log->info('.idl file found: ' . $zip->getNameIndex($i));
                 $this->idlFile = $zip->getNameIndex($i);
             }
         }
         // Example inputs.
         if (stripos($zip->getNameIndex($i), 'examples/') === 0 && ProblemDeployer::endsWith($zip->getNameIndex($i), '.in', true)) {
             $this->filesToUnzip[] = $zip->getNameIndex($i);
         }
     }
     $this->checkedForInteractive = true;
     if ($this->isInteractive) {
         if ($this->idlFile == null) {
             throw new InvalidParameterException('problemDeployerIdlMissing');
         } elseif (!in_array('interactive/examples/sample.in', $this->filesToUnzip)) {
             throw new InvalidParameterException('problemDeployerInteractiveSampleMissing');
         }
     }
     if ($this->isInteractive && $size > ProblemDeployer::MAX_INTERACTIVE_ZIP_FILESIZE) {
         throw new InvalidParameterException('problemDeployerExceededZipSizeLimit', null, array('size' => $size, 'max_size' => ProblemDeployer::MAX_INTERACTIVE_ZIP_FILESIZE));
     } elseif ($size > ProblemDeployer::MAX_ZIP_FILESIZE) {
         throw new InvalidParameterException('problemDeployerExceededZipSizeLimit', null, array('size' => $size, 'max_size' => ProblemDeployer::MAX_ZIP_FILESIZE));
     }
     try {
         // Look for testplan
         if (in_array('testplan', $zipFilesArray)) {
             $returnValue = $this->checkCasesWithTestplan($zip, $zipFilesArray);
             $this->log->info('testplan found, checkCasesWithTestPlan=' . $returnValue);
             $this->filesToUnzip[] = 'testplan';
         } else {
             $this->log->info('testplan not found');
             $this->checkCases($zip, $zipFilesArray);
         }
         // Log files to unzip
         $this->log->info('Files to unzip: ');
         foreach ($this->filesToUnzip as $file) {
             $this->log->info($file);
         }
         // Look for statements
         $returnValue = $this->checkProblemStatements($zipFilesArray, $zip);
         $this->log->info('checkProblemStatements=' . $returnValue . '.');
     } finally {
         // Close zip
         $this->log->info('closing zip');
         $zip->close();
     }
     return $returnValue;
 }
Ejemplo n.º 3
0
		public function procShopToolExportProducts(){
			$shopModel = $this->model;
			$productRepository = $shopModel->getProductRepository();
            $categoryRepository = $shopModel->getCategoryRepository();
            $attributeRepository = $shopModel->getAttributeRepository();

			$args = new stdClass();
			$args->module_srl = $this->module_info->module_srl;

			$products = $productRepository->getAllProducts($args);
            $categories = $categoryRepository->getCategoriesTree($args->module_srl)->toFlatStructure();
            $attributes = $attributeRepository->getAttributesList($args->module_srl)->attributes;

            FileHandler::makeDir('./files/attach/shop/export-import/');
            if(count($products)) $productRepository->addProductsToExportFolder($products);
            if(count($categories)) $categoryRepository->addCategoriesToExportFolder($categories);
            if(count($attributes)) $attributeRepository->addAttributesToExportFolder($attributes);
            if(!count($products) && !count($categories) && !count($attributes)){
                $this->setMessage("No data to export");
                $returnUrl = getNotEncodedUrl('', 'act', 'dispShopToolManageProducts');
                $this->setRedirectUrl($returnUrl);
                return;
            }
            $shopModel->includeZipHandler();

            ZipHandler::zip('./files/attach/shop/export-import/','./files/attach/shop/export.zip');

            header("Content-type: application/zip");
            header("Content-Disposition: attachment; filename=export.zip");
            header("Pragma: no-cache");
            header("Expires: 0");

            readfile('./files/attach/shop/export.zip');

            FileHandler::removeFile('./files/attach/shop/export.zip');
            FileHandler::removeDir('./files/attach/shop/export-import/');

            exit;
		}