/** * Construct storage object. The first parameter $directory states the * working directory, in which all file modifications will take place. * * @param string $directory * @throws Opus_Storage_Exception */ public function __construct($directory = null, $subdirectory = null) { if (!is_dir($directory)) { throw new Opus_Storage_Exception("Storage directory '{$directory}' does not exist. (cwd: " . getcwd() . ")"); } if (!is_executable($directory)) { throw new Opus_Storage_Exception("Storage directory '{$directory}' is not executable. (cwd: " . getcwd() . ")"); } $this->filesDirectory = Opus_Util_File::addDirectorySeparator($directory); $this->subDirectory = Opus_Util_File::addDirectorySeparator($subdirectory); }
/** * Remove a directory and its entries recursivly. * * @param string $dir Directory to delete. * @return bool Result of rmdir() call. */ public static function deleteDirectory($dir) { if (false === file_exists($dir)) { return true; } if (false === is_dir($dir)) { return unlink($dir); } foreach (scandir($dir) as $item) { if ($item == '.' || $item == '..') { continue; } if (false === Opus_Util_File::deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) { return false; } } return rmdir($dir); }
public function testRequestPublishedDocWithAccessibleFile() { $this->markTestIncomplete('build breaks when running this test on ci system -- it seems that phpunit does not allow to test for file downloads'); // create test file test.pdf in file system $config = Zend_Registry::get('Zend_Config'); $path = $config->workspacePath . DIRECTORY_SEPARATOR . uniqid(); mkdir($path, 0777, true); $filepath = $path . DIRECTORY_SEPARATOR . 'test.pdf'; touch($filepath); $doc = $this->createTestDocument(); $doc->setServerState('published'); $file = new Opus_File(); $file->setVisibleInOai(true); $file->setPathName('test.pdf'); $file->setTempFile($filepath); $doc->addFile($file); $doc->store(); $this->dispatch('/oai/container/index/docId/' . $doc->getId()); // cleanup $file->delete(); Opus_Util_File::deleteDirectory($path); $this->assertResponseCode(200); }
private function deleteTestFiles() { if (!is_null($this->testFiles)) { foreach ($this->testFiles as $key => $filepath) { try { Opus_Util_File::deleteDirectory(dirname($filepath)); } catch (Exception $e) { } } } }