예제 #1
0
 public function testZipDirectory()
 {
     $objFileSystem = new class_filesystem();
     echo "\t creating test structure\n";
     $objFileSystem->folderCreate("/files/cache/ziptest");
     $this->assertFileExists(_realpath_ . "/files/cache/ziptest", __FILE__ . " checkFileNotExists");
     $objFileSystem->folderCreate("/files/cache/ziptest/subdir");
     $objFileSystem->fileCopy(class_resourceloader::getInstance()->getCorePathForModule("module_system") . "/module_system/metadata.xml", "/files/cache/ziptest/licence_lgpl1.txt");
     $objFileSystem->fileCopy(class_resourceloader::getInstance()->getCorePathForModule("module_system") . "/module_system/metadata.xml", "/files/cache/ziptest/licence_lgpl2.txt");
     $objFileSystem->fileCopy(class_resourceloader::getInstance()->getCorePathForModule("module_system") . "/module_system/metadata.xml", "/files/cache/ziptest/subdir/licence_lgpl.txt");
     echo "\ttesting class_zip...\n";
     $objZip = new class_zip();
     echo "\topening test.zip\n";
     $this->assertTrue($objZip->openArchiveForWriting("/files/cache/test.zip"), __FILE__ . " openArchive");
     $this->assertTrue($objZip->addFolder("/files/cache/ziptest"), __FILE__ . " addFolder");
     $this->assertTrue($objZip->closeArchive(), __FILE__ . " closeArchive");
     $this->assertFileExists(_realpath_ . "/files/cache/test.zip", __FILE__ . " checkFileExists");
     echo "\textracting files\n";
     $objFileSystem->folderCreate("/files/cache/zipextract");
     $this->assertFileExists(_realpath_ . "/files/cache/zipextract", __FILE__ . " checkFileExists");
     $objZip = new class_zip();
     $this->assertTrue($objZip->extractArchive("/files/cache/test.zip", "/files/cache/zipextract"), __FILE__ . " extractArchive");
     $this->assertFileExists(_realpath_ . "/files/cache/zipextract/files/cache/ziptest/licence_lgpl1.txt", __FILE__ . " extractArchive");
     $this->assertFileExists(_realpath_ . "/files/cache/zipextract/files/cache/ziptest/licence_lgpl2.txt", __FILE__ . " extractArchive");
     $this->assertFileExists(_realpath_ . "/files/cache/zipextract/files/cache/ziptest/subdir/licence_lgpl.txt", __FILE__ . " extractArchive");
     echo "\tremoving testfile\n";
     $this->assertTrue($objFileSystem->fileDelete("/files/cache/test.zip"), __FILE__ . " deleteFile");
     $this->assertFileNotExists(_realpath_ . "/files/cache/test.zip", __FILE__ . " checkFileNotExists");
     $objFileSystem->folderDeleteRecursive("/files/cache/ziptest");
     $this->assertFileNotExists(_realpath_ . "/files/cache/ziptest", __FILE__ . " checkFileNotExists");
     $objFileSystem->folderDeleteRecursive("/files/cache/zipextract");
     $this->assertFileNotExists(_realpath_ . "/files/cache/zipextract", __FILE__ . " checkFileNotExists");
 }
 /**
  * @see interface_admin_systemtask::executeTask()
  * @return string
  */
 public function executeTask()
 {
     if (!class_module_system_module::getModuleByName("system")->rightRight2()) {
         return $this->getLang("commons_error_permissions");
     }
     $strFilename = "/backup_" . time() . ".zip";
     $objZip = new class_zip();
     $objZip->openArchiveForWriting($strFilename);
     foreach ($this->arrFoldersToInclude as $strOneFolder) {
         $objZip->addFolder($strOneFolder);
     }
     foreach ($this->arrFilesToInclude as $strOneFile) {
         $objZip->addFile($strOneFile);
     }
     if ($objZip->closeArchive()) {
         return $this->getLang("systemtask_filedump_success") . $strFilename;
     } else {
         return $this->getLang("systemtask_filedump_error");
     }
 }