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; }
public function testZipSingleFolder() { mkdir('extracted'); $this->assertTrue(Compression::zip('hiDir', 'hi.zip')); $this->assertTrue(file_exists('hi.zip')); $this->assertFalse(file_exists('extracted/hi.txt')); $this->assertFalse(file_exists('extracted/hiDir')); $this->assertTrue(Compression::unzip('hi.zip', 'extracted')); $this->assertTrue(file_exists('extracted/hi.txt')); $this->assertFalse(file_exists('extracted/hiDir/hi.txt')); unlink('hi.zip'); unlink('extracted/hi.txt'); rmdir('extracted'); }
/** * Packs contents of output folder into ZIP archive. * @return mixed path (string) of ZIP archive with packed output, or null if * no output files were created during plugin execution */ private function packOutput() { $outputFile = null; if ($this->outputFolder != null && is_dir($this->outputFolder) && count(glob($this->outputFolder . DIRECTORY_SEPARATOR . '*')) > 0) { $outputFile = tempnam(sys_get_temp_dir(), ''); if (!Compression::zip($this->outputFolder, $outputFile)) { $outputFile = null; } } return $outputFile; }