protected function body() { if (!$this->userHasPrivileges(User::pluginsAdd)) { return false; } $inputs = array('name' => array('isName', 'isNotEmpty')); if (!$this->isInputValid($inputs)) { return false; } $name = $this->getParams('name'); $existingPluginsWithSameName = Repositories::getRepository(Repositories::Plugin)->findBy(['name' => $name]); if (count($existingPluginsWithSameName) > 0) { return $this->death(StringID::PluginNameAlreadyExists); } $pluginFile = $this->getUploadedFile('plugin'); if (!$pluginFile) { return false; } $pluginFolder = Config::get('paths', 'plugins') . $name; if (file_exists($pluginFolder)) { return $this->death(StringID::PluginFolderAlreadyExists); } if (!Filesystem::createDir($pluginFolder)) { return $this->death(StringID::FileSystemError); } if (!Compression::unzip($pluginFile, $pluginFolder)) { $this->death(StringID::UnzipUnsuccessful); goto cleanup_error; } $manifestFile = $pluginFolder . DIRECTORY_SEPARATOR . 'manifest.xml'; $manifest = null; if (!($manifest = $this->parsePluginManifest($manifestFile))) { $this->death(StringID::BadlyFormedPlugin); goto cleanup_error; } if (!file_exists($pluginFolder . DIRECTORY_SEPARATOR . $manifest['mainFile'])) { $this->death(StringID::BadlyFormedPlugin); goto cleanup_error; } $plugin = new \Plugin(); $plugin->setIdentifier($manifest['identifier']); $plugin->setDescription($manifest['description']); $plugin->setConfig($manifest['arguments']); $plugin->setMainfile($name . '/' . $manifest['mainFile']); $plugin->setName($name); $plugin->setType($manifest['type']); Repositories::persistAndFlush($plugin); Filesystem::removeFile($pluginFile); return true; cleanup_error: Filesystem::removeDir($pluginFolder); Filesystem::removeFile($pluginFile); return false; }
protected function body() { if (!$this->isInputValid(array('id' => 'isIndex'))) { return false; } $id = $this->getParams('id'); /** * @var $attachment \Attachment */ $attachment = Repositories::findEntity(Repositories::Attachment, $id); if (!$this->authorizedToManageLecture($attachment->getLecture())) { return false; } $folder = Config::get('paths', 'attachments'); $file = $attachment->getFile(); RemovalManager::deleteAttachmentById($id); Filesystem::removeFile($folder . $file); return true; }
public function testRemoveFile() { touch('kaktus'); $this->assertTrue(Filesystem::removeFile('kaktus')); $this->assertFalse(file_exists('kaktus')); }
/** * Deletes test with supplied ID (with input & output files). * @param int $id test ID * @return array error properties provided by removalError() or retrievalError(), * or false in case of success */ public static function deleteTestById($id) { /** * @var $test \PluginTest */ $test = Repositories::findEntity(Repositories::PluginTest, $id); $testFolder = Config::get('paths', 'tests'); // Delete input solution file if (is_file(Filesystem::combinePaths($testFolder, $test->getInput()))) { Filesystem::removeFile(Filesystem::combinePaths($testFolder, $test->getInput())); } // Delete plugin test output if (is_file(Filesystem::combinePaths($testFolder, $test->getOutput()))) { Filesystem::removeFile(Filesystem::combinePaths($testFolder, $test->getOutput())); } Repositories::remove($test); return false; }
protected function tearDown() { \asm\utils\Filesystem::removeFile("myconfig.ini"); \asm\utils\Filesystem::removeFile("myconfig2.ini"); }