public function testCreateDir()
 {
     $this->assertFalse(Filesystem::createDir(self::TEST_DIRECTORY . "/a.txt"));
     $this->assertTrue(Filesystem::createDir(self::TEST_DIRECTORY . "/a/b/c"));
     $this->assertTrue(is_dir(self::TEST_DIRECTORY . "/a/b"));
     $this->assertTrue(is_dir(self::TEST_DIRECTORY . "/a"));
     $this->assertTrue(is_dir(self::TEST_DIRECTORY . "/a/b/c"));
     Filesystem::removeDir(self::TEST_DIRECTORY . "/a");
     $this->assertFalse(file_exists(self::TEST_DIRECTORY . "/a"));
 }
Пример #2
0
 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;
 }
Пример #3
0
 /**
  * (Creates and) sets folder for log files to be saved in.
  * @param string $folder logfile folder
  */
 private function __construct($folder)
 {
     Filesystem::createDir($folder, 0700);
     $this->folder = realpath($folder);
 }