delete() public method

Deletes the directory
public delete ( boolean $keep = false ) : boolean
$keep boolean Set this to true to keep the directory but delete all its content
return boolean
 /**
  * Execution method always used for tasks
  *
  * @return void
  */
 public function execute()
 {
     parent::execute();
     //引数のセット
     if (isset($this->params[self::KEY_APACHE_OWNER])) {
         $owner = Hash::get($this->params, self::KEY_APACHE_OWNER);
         $writables = array(APP . 'Config', APP . 'tmp', ROOT . DS . 'composer.json', ROOT . DS . 'bower.json');
         foreach ($writables as $file) {
             $messages = array();
             $ret = null;
             $cmd = sprintf('`which chown` %s -R %s 2>&1', $owner, $file);
             exec($cmd, $messages, $ret);
         }
     }
     if (array_key_exists(self::KEY_RELEASE, $this->params)) {
         $path = ROOT . DS . 'app' . DS . 'Plugin' . DS;
         $plugins = array_unique(array_merge(App::objects('plugins'), array_map('basename', glob($path . '*', GLOB_ONLYDIR))));
         $folder = new Folder();
         foreach ($plugins as $plugin) {
             $folder->delete($path . $plugin . DS . '.git');
         }
         $folder->delete(ROOT . DS . '.git');
         $folder->delete(ROOT . DS . '.chef');
     }
     Configure::write('NetCommons.installed', true);
     $this->InstallUtil->saveAppConf();
 }
 function endTest()
 {
     $folder = new Folder(TMP);
     $folder->delete(ROOT . DS . APP_DIR . DS . 'webroot' . DS . 'files' . DS . 'test_upload');
     $folder->delete(ROOT . DS . APP_DIR . DS . 'tmp' . DS . 'tests' . DS . 'path');
     Classregistry::flush();
     unset($this->TestUpload);
 }
Beispiel #3
0
 /**
  * Make sure if the $appPath exists and copy the skel to there
  * @param string $appPath
  */
 public function initialAppPath($appPath)
 {
     App::uses('Folder', 'Utility');
     $fh = new Folder();
     if (file_exists($appPath)) {
         if (false === $fh->delete($appPath)) {
             $this->errorMessage = __('Target path exists. But the program could not delete the folder automatically');
             return false;
         } else {
             $this->tasks[] = array('title' => __('Target path exists. Delete the old folders.'), 'operactions' => $fh->messages());
         }
     }
     /*
      * Copy the skelecton of the application
      */
     $fh->copy(array('to' => $appPath, 'from' => VENDORS . 'olc_baker' . DS . 'skels' . DS . 'default', 'mode' => 0777));
     $errors1 = $fh->errors();
     $fh->copy(array('to' => $appPath . DS . 'cake2' . DS . 'lib', 'from' => CAKE_CORE_INCLUDE_PATH, 'mode' => 0777));
     $errors2 = $fh->errors();
     if (!empty($errors1) || !empty($errors2)) {
         $this->errorMessage = __('The program could not copy files to the folder automatically');
         return false;
     } else {
         $this->tasks[] = array('title' => __('Copy the skelecton of application to the target path'), 'operactions' => $fh->messages());
     }
     return true;
 }
 function __cleanUp()
 {
     $Cleanup = new Folder(TMP . 'tests/git');
     if ($Cleanup->pwd() == TMP . 'tests/git') {
         $Cleanup->delete();
     }
 }
Beispiel #5
0
 /**
  * Delete directory for upload test.
  *
  * @return void
  */
 public function tearDownFiles()
 {
     //アップロードテストのためのディレクトリ削除
     $folder = new Folder();
     $folder->delete(TMP . 'tests' . DS . 'files');
     unset($folder);
 }
Beispiel #6
0
 /**
  * Remove a pasta .git
  */
 function _excludeGitFolder($pluginPath)
 {
     App::import('Folder');
     $gitFolder = $pluginPath . DS . '.git' . DS;
     $folder = new Folder($gitFolder, false);
     $folder->delete($gitFolder);
 }
 public function tearDown()
 {
     parent::tearDown();
     // clean up test upload dir
     $this->UploadFolder->delete();
     unset($this->UploadFolder);
 }
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     $Folder = new Folder($this->Task->path . 'bake_test_app');
     $Folder->delete();
     unset($this->Task);
 }
Beispiel #9
0
 /**
  * The main method: where things happen
  * 
  * @access public
  */
 function main()
 {
     if (isset($this->params['quiet'])) {
         $this->quiet = true;
     }
     $tmp = new Folder(TMP);
     $folders = reset($tmp->read());
     // read only directories (array[0])
     foreach ($folders as $folder) {
         $tmp->cd(TMP);
         $tmp->cd($folder);
         $files = end($tmp->read());
         // read only files (array[1])
         if (in_array('last_interaction', $files)) {
             $file_interaction = (int) file_get_contents($tmp->pwd() . DS . 'last_interaction');
             // as each piece is 1Mb, this will give the user the chance of uploading at 13,7 kbps (1,7 kb/s)
             if (time() - $file_interaction > 600) {
                 $this->out("Removing {$folder}");
                 foreach ($files as $file) {
                     unlink($tmp->pwd() . DS . $file);
                 }
                 $tmp->delete();
             }
         }
     }
 }
Beispiel #10
0
 /**
  * Performs the initial git-svn clone of plugins.
  *
  * This shell grabs plugins that require their initial clone in the order
  * they were requested, and clones them from the WordPress SVN repository.
  *
  * If unspecified, a maximum of 5 plugins will be cloned with one run.
  *
  * @return int Shell return code.
  */
 function main()
 {
     $max = 5;
     if (isset($this->args[0]) && is_numeric($this->args[0]) && $this->args[0] > 0) {
         $max = (int) $this->args[0];
     }
     $plugins = $this->Plugin->findByState('cloning', array('contain' => array('PluginsState' => array('State')), 'order' => array('InnerPluginsState.modified'), 'limit' => $max));
     if (count($plugins) == 0) {
         $this->out(__('<info>No plugins need to be cloned.</info>'));
         $this->_unlock();
         return 0;
     }
     $this->out(__('Cloning %d plugins...', count($plugins)));
     $dir = new Folder(TMP . 'git', true, 0755);
     $error = implode(', ', $dir->errors());
     if (!empty($error)) {
         $this->_unlock();
         $this->error(__('Filesystem Error'), __('Failed to create git clone directory: %s', $error));
     }
     $dir = new Folder(TMP . 'logs' . DS . 'git', true, 0755);
     $error = implode(', ', $dir->errors());
     if (!empty($error)) {
         $this->_unlock();
         $this->error(__('Filesystem Error'), __('Failed to create git logs directory: %s', $error));
     }
     foreach ($plugins as $plugin) {
         $this->out(__('Cloning: "%s" (%d)', $plugin['Plugin']['slug'], $plugin['Plugin']['id']));
         $svn_url = sprintf(Configure::read('App.plugin_svn_url'), $plugin['Plugin']['slug']);
         $git_path = sprintf(Configure::read('App.plugin_repo_path'), $plugin['Plugin']['slug']);
         $log_path = TMP . 'logs' . DS . 'git' . DS . $plugin['Plugin']['slug'] . '.log';
         // Clear out any existing git-svn clone attempt that failed before.
         $git_dir = new Folder($git_path);
         $git_dir->delete();
         try {
             $this->_exec('git svn clone -qq --prefix=svn/ -s %s %s >> %s 2>&1', $svn_url, $git_path, $log_path);
         } catch (RuntimeException $e) {
             $this->out(__('<warning>Failed to clone "%s", please check the git log file.</warning>', $plugin['Plugin']['slug']));
             $this->PluginsState->touch($plugin['InnerPluginsState']['id']);
             continue;
         }
         if (!$this->_createGithubRepo($plugin['Plugin']['slug'])) {
             $this->PluginsState->touch($plugin['InnerPluginsState']['id']);
             continue;
         }
         if (!$this->PluginsState->findOrCreate($plugin['Plugin']['id'], 'cloned') || !$this->PluginsState->findOrCreate($plugin['Plugin']['id'], 'updating')) {
             $this->out(__('<warning>Failed marking plugin as cloned.</warning>'));
             // Even though this plugin cloned successfully, if we can't
             // mark it as cloned, we don't want it to slip into limbo, so
             // we'll let it attempt to do the full clone all over again.
             $this->PluginsState->touch($plugin['InnerPluginsState']['id']);
             continue;
         }
         if (!$this->PluginsState->delete($plugin['InnerPluginsState']['id'])) {
             $this->out(__('<warning>Failed removing "cloning" state on cloned plugin.</warning>'));
         }
     }
     $this->out(__('<info>Finished cloning plugins.</info>'));
     $this->_unlock();
     return 0;
 }
Beispiel #11
0
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     unset($this->Task);
     $Folder = new Folder($this->path);
     $Folder->delete();
 }
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     unset($this->Package);
     $Folder = new Folder(TMP . DS . 'repos');
     $Folder->delete();
     parent::tearDown();
 }
Beispiel #13
0
 public function afterDelete()
 {
     parent::afterDelete();
     $files = new Folder('files/Disography/' . $this->id);
     $files->delete();
     $cover = new Folder('files/Cover/' . $this->id);
     $cover->delete();
 }
 function endTest()
 {
     App::import('Folder');
     $folder = new Folder(FOUR_PLUGIN_LOCATION);
     if (file_exists($folder->path)) {
         $folder->delete();
     }
 }
 function endTest()
 {
     $Cleanup = new Folder(TMP . 'tests/git');
     if ($Cleanup->pwd() == TMP . 'tests/git') {
         $Cleanup->delete();
     }
     unset($this->Source);
 }
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     $this->File->close();
     unset($this->File);
     $Folder = new Folder();
     $Folder->delete(TMP . 'tests' . DS . 'permissions');
 }
Beispiel #17
0
 function end()
 {
     parent::end();
     $Cleanup = new Folder(TMP . 'tests/svn');
     if ($Cleanup->pwd() == TMP . 'tests/svn') {
         $Cleanup->delete();
     }
 }
 function startup(&$controller)
 {
     if ($controller->data && in_array($controller->action, $this->clearActions)) {
         App::import('core', 'Folder');
         $Folder = new Folder();
         $Folder->delete(WWW_ROOT . 'cache');
     }
 }
Beispiel #19
0
 /**
  * testSaveFile
  */
 public function testSaveFile()
 {
     $data = array('Page' => array('title' => 'Title', 'body' => '<p>This is a test page.</p>', 'slug' => '', 'image' => array('name' => '4df14a7d677.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/tmp/phpX6Iota', 'error' => 0, 'size' => 33575)));
     $result = $this->Page->save($data);
     $this->assertEquals('24eb8c4cdef7a0c9f51d23351df02dfb.jpg', $result['Page']['image']);
     $dir = new Folder(Configure::read('Oven.config.upload_location') . 'pages');
     // TODO: Check if file created in folder
     $dir->delete();
 }
Beispiel #20
0
 /**
  * delete folder
  * 
  */
 public function deleteFolder($user_id, $folder_id = null, $listFolderShop = null)
 {
     App::uses('Folder', 'Utility');
     $folder = new Folder();
     if (empty($folder_id)) {
         return false;
     }
     if (!empty($listFolderShop)) {
         foreach ($listFolderShop as $shop_id) {
             $realPath = WWW_ROOT . 'shops' . DS . $user_id . DS . $folder_id;
             $realPath = $realPath . DS . $shop_id . DS;
             $folder->delete($realPath);
         }
     } else {
         $realPath = WWW_ROOT . 'shops' . DS . $user_id . DS . $folder_id;
         $folder->delete($realPath);
     }
 }
 function _excludeGitFolder()
 {
     if (!App::import('Folder')) {
         $this->out(__d('plugin', "Impossivel caregar 'Folder'"));
     }
     $gitFolder = APP . 'plugins/improved_cake_shell/.git/';
     $folder = new Folder();
     $folder->delete($gitFolder);
 }
Beispiel #22
0
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     unset($this->Task);
     $Folder = new Folder($this->path);
     $Folder->delete();
     App::build();
     CakePlugin::unload();
 }
Beispiel #23
0
 public static function delete($alias)
 {
     $viewPath = App::path('View');
     $folder = new Folder($viewPath[0] . 'Themed' . DS . $alias . DS);
     if ($folder->delete()) {
         return true;
     }
     return false;
 }
 /**
  * tearDown
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     $path = CakePlugin::path('Extensions') . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'Example';
     $Folder = new Folder($path);
     $Folder->delete();
     $path = CakePlugin::path('Extensions') . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'Minimal';
     $Folder = new Folder($path);
     $Folder->delete();
 }
Beispiel #25
0
 function __cleanUp()
 {
     $path = Configure::read('Content.base');
     $Cleanup = new Folder(TMP . 'tests/git');
     if ($Cleanup->pwd() == TMP . 'tests/git') {
         $Cleanup->delete();
     }
     @unlink($path . 'chaw');
     @unlink($path . 'permissions.ini');
 }
Beispiel #26
0
 /**
  *
  */
 protected function removeCacheDir()
 {
     if (is_dir(TL_ROOT . '/system/cache/timelinejs')) {
         // Purge the folder
         $objFolder = new \Folder('system/cache/timelinejs');
         $objFolder->purge();
         $objFolder->delete();
         // Add a log entry
         \Controller::log('Removed not used timelinejs cache directory', 'TimelineJSRunOnce run()', TL_CRON);
     }
 }
 /**
  * インストール 
  * 
  * cake bc_manager install "サイト名" "データベースの種類" "管理者アカウント名" "管理者パスワード" "管理者Eメール" -host "DBホスト名" -database "DB名" -login "DBユーザー名" -password "DBパスワード" -prefix "DBプレフィックス" -port "DBポート" -baseurl "RewriteBaseに設定するURL"
  */
 public function install()
 {
     if (BC_INSTALLED) {
         $this->err("既にインストール済です。 cake bc_manager reset を実行してください。");
         return;
     }
     if (Configure::read('debug') != -1) {
         $this->err('baserCMSのインストールを行うには、debug を -1 に設定する必要があります。');
         return false;
     }
     if (!$this->_install()) {
         $this->err("baserCMSのインストールに失敗しました。ログファイルを確認してください。");
     }
     $Folder = new Folder();
     $Folder->delete(TMP . 'cache');
     $Folder->delete(TMP . 'logs');
     $Folder->delete(TMP . 'schemas');
     $Folder->delete(TMP . 'sessions');
     $this->out("baserCMSのインストールが完了しました。");
 }
Beispiel #28
0
 /**
  * testAddTestDirectoryRecursiveWithNonPhp
  *
  * @return void
  */
 public function testAddTestDirectoryRecursiveWithNonPhp()
 {
     $this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
     $Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
     touch($Folder->path . DS . 'BackupTest.php~');
     touch($Folder->path . DS . 'SomeNotesTest.txt');
     touch($Folder->path . DS . 'NotHiddenTest.php');
     $suite = $this->getMock('CakeTestSuite', array('addTestFile'));
     $suite->expects($this->exactly(1))->method('addTestFile');
     $suite->addTestDirectoryRecursive($Folder->pwd());
     $Folder->delete();
 }
 /**
  * afterDelete
  *
  * No need to use an adapter here, just delete the whole folder using cakes Folder class
  *
  * @param CakeEvent $Event
  * @return void
  */
 public function afterDelete(CakeEvent $Event)
 {
     if ($this->_checkEvent($Event)) {
         $Model = $Event->subject();
         $path = Configure::read('Media.basePath') . $Event->data['record'][$Model->alias]['path'];
         if (is_dir($path)) {
             $Folder = new Folder($path);
             return $Folder->delete();
         }
         return false;
     }
 }
Beispiel #30
0
 /**
  * tearDown
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     $Folder = new Folder(TMP);
     $files = $Folder->find('croogo_.*');
     foreach ($files as $file) {
         unlink(TMP . $file);
     }
     $Folder = new Folder(TESTS . 'test_app' . DS . 'Plugin' . DS . 'Example');
     $Folder->delete();
     $Folder = new Folder(TESTS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'Minimal');
     $Folder->delete();
 }