/** * 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; }
/** * 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; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $data = Input::except(array('_token', '_method')); $trimmedData = $this->trimData($data, array()); $folder = Folder::where('name', $trimmedData['name'])->get()->first(); if (!empty($folder)) { Session::flash('flash_error', trans('message.folder.error.already_exist')); return Redirect::route('secured.folder.create')->withInput(); } $currentUser = $this->getCurrentUser(); $folder = new Folder(); $folder->fill($trimmedData); $folder->owner_id = $currentUser->id; if (!$folder->save()) { $errors = $folder->errors(); return Redirect::route('secured.folder.create')->withInput()->withErrors($errors); } return Redirect::route('secured.folder.index'); }
/** * Bake the plugin, create directories and files * * @params $plugin name of the plugin in CamelCased format * @access public * @return bool */ function bake($plugin) { $pluginPath = Inflector::underscore($plugin); $this->hr(); $this->out("Plugin Name: {$plugin}"); $this->out("Plugin Directory: {$this->path}{$pluginPath}"); $this->hr(); $looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y'); if (low($looksGood) == 'y' || low($looksGood) == 'yes') { $verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n'); $Folder = new Folder($this->path . $pluginPath); $directories = array('models' . DS . 'behaviors', 'controllers' . DS . 'components', 'views' . DS . 'helpers'); foreach ($directories as $directory) { $Folder->create($this->path . $pluginPath . DS . $directory); } if (low($verbose) == 'y' || low($verbose) == 'yes') { foreach ($Folder->messages() as $message) { $this->out($message); } } $errors = $Folder->errors(); if (!empty($errors)) { return false; } $controllerFileName = $pluginPath . '_app_controller.php'; $out = "<?php\n\n"; $out .= "class {$plugin}AppController extends AppController {\n\n"; $out .= "}\n\n"; $out .= "?>"; $this->createFile($this->path . $pluginPath . DS . $controllerFileName, $out); $modelFileName = $pluginPath . '_app_model.php'; $out = "<?php\n\n"; $out .= "class {$plugin}AppModel extends AppModel {\n\n"; $out .= "}\n\n"; $out .= "?>"; $this->createFile($this->path . $pluginPath . DS . $modelFileName, $out); $this->hr(); $this->out(sprintf(__("Created: %s in %s", true), $plugin, $this->path . $pluginPath)); $this->hr(); } return true; }
/** * Bake the plugin, create directories and files * * @param string $plugin Name of the plugin in CamelCased format * @return bool */ public function bake($plugin) { $pathOptions = App::path('plugins'); if (count($pathOptions) > 1) { $this->findPath($pathOptions); } $this->hr(); $this->out(__d('cake_console', "<info>Plugin Name:</info> %s", $plugin)); $this->out(__d('cake_console', "<info>Plugin Directory:</info> %s", $this->path . $plugin)); $this->hr(); $looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n', 'q'), 'y'); if (strtolower($looksGood) === 'y') { $Folder = new Folder($this->path . $plugin); $directories = array('Config' . DS . 'Schema', 'Model' . DS . 'Behavior', 'Model' . DS . 'Datasource', 'Console' . DS . 'Command' . DS . 'Task', 'Controller' . DS . 'Component', 'Lib', 'View' . DS . 'Helper', 'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component', 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper', 'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior', 'Test' . DS . 'Fixture', 'Vendor', 'webroot'); foreach ($directories as $directory) { $dirPath = $this->path . $plugin . DS . $directory; $Folder->create($dirPath); new File($dirPath . DS . 'empty', true); } foreach ($Folder->messages() as $message) { $this->out($message, 1, Shell::VERBOSE); } $errors = $Folder->errors(); if (!empty($errors)) { foreach ($errors as $message) { $this->error($message); } return false; } $controllerFileName = $plugin . 'AppController.php'; $out = "<?php\n\n"; $out .= "App::uses('AppController', 'Controller');\n\n"; $out .= "class {$plugin}AppController extends AppController {\n\n"; $out .= "}\n"; $this->createFile($this->path . $plugin . DS . 'Controller' . DS . $controllerFileName, $out); $modelFileName = $plugin . 'AppModel.php'; $out = "<?php\n\n"; $out .= "App::uses('AppModel', 'Model');\n\n"; $out .= "class {$plugin}AppModel extends AppModel {\n\n"; $out .= "}\n"; $this->createFile($this->path . $plugin . DS . 'Model' . DS . $modelFileName, $out); $this->_modifyBootstrap($plugin); $this->hr(); $this->out(__d('cake_console', '<success>Created:</success> %s in %s', $plugin, $this->path . $plugin), 2); } return true; }
/** * testDelete method * * @return void */ public function testDelete() { $path = TMP . 'folder_delete_test'; mkdir($path); touch($path . DS . 'file_1'); mkdir($path . DS . 'level_1_1'); touch($path . DS . 'level_1_1' . DS . 'file_1_1'); mkdir($path . DS . 'level_1_1' . DS . 'level_2_1'); touch($path . DS . 'level_1_1' . DS . 'level_2_1' . DS . 'file_2_1'); touch($path . DS . 'level_1_1' . DS . 'level_2_1' . DS . 'file_2_2'); mkdir($path . DS . 'level_1_1' . DS . 'level_2_2'); $Folder = new Folder($path, true); $return = $Folder->delete(); $this->assertTrue($return); $messages = $Folder->messages(); $errors = $Folder->errors(); $this->assertEquals(array(), $errors); $expected = array($path . DS . 'file_1 removed', $path . DS . 'level_1_1' . DS . 'file_1_1 removed', $path . DS . 'level_1_1' . DS . 'level_2_1' . DS . 'file_2_1 removed', $path . DS . 'level_1_1' . DS . 'level_2_1' . DS . 'file_2_2 removed', $path . DS . 'level_1_1' . DS . 'level_2_1 removed', $path . DS . 'level_1_1' . DS . 'level_2_2 removed', $path . DS . 'level_1_1 removed', $path . ' removed'); sort($expected); sort($messages); $this->assertEquals($expected, $messages); }
/** * testDelete method * * @return void */ public function testDelete() { $path = TMP . 'folder_delete_test'; $Folder = new Folder($path, true); touch(TMP . 'folder_delete_test' . DS . 'file1'); touch(TMP . 'folder_delete_test' . DS . 'file2'); $return = $Folder->delete(); $this->assertTrue($return); $messages = $Folder->messages(); $errors = $Folder->errors(); $this->assertEquals($errors, array()); $expected = array($path . ' created', $path . DS . 'file1 removed', $path . DS . 'file2 removed', $path . ' removed'); $this->assertEquals($expected, $messages); }
/** * Delete theme * * @param string $alias Theme alias * @return boolean true when successful, false or array or error messages when failed * @throws InvalidArgumentException * @throws UnexpectedValueException */ public function delete($alias) { if (empty($alias)) { throw new InvalidArgumentException(__d('croogo', 'Invalid theme')); } $paths = array(APP . 'webroot' . DS . 'theme' . DS . $alias, APP . 'View' . DS . 'Themed' . DS . $alias); $folder = new Folder(); foreach ($paths as $path) { if (!file_exists($path)) { continue; } if (is_link($path)) { return unlink($path); } elseif (is_dir($path)) { if ($folder->delete($path)) { return true; } else { return $folder->errors(); } } } throw new UnexpectedValueException(__d('croogo', 'Theme %s not found', $alias)); }
/** * Delete plugin * * @param string $plugin Plugin name * @return boolean true when successful, false or array of error messages when failed * @throws InvalidArgumentException */ public function delete($plugin) { if (empty($plugin)) { throw new InvalidArgumentException(__d('croogo', 'Invalid plugin')); } $pluginPath = APP . 'Plugin' . DS . $plugin; if (is_link($pluginPath)) { return unlink($pluginPath); } $folder = new Folder(); $result = $folder->delete($pluginPath); if ($result !== true) { return $folder->errors(); } return true; }
/** * Delete plugin * * @param string $plugin Plugin name * @return boolean true when successful, false or array of error messages when failed */ public function delete($plugin) { $pluginPath = APP . 'Plugin' . DS . $plugin; $folder = new Folder(); $result = $folder->delete($pluginPath); if ($result !== true) { return $folder->errors(); } return true; }
/** * Bake the plugin, create directories and files * * @params $plugin name of the plugin in CamelCased format * @access public * @return bool */ function bake($plugin) { $pluginPath = $plugin; if (substr($pluginPath, 0, 2) !== 'Cc') { $this->err('Plugin name must start with "Cc"'); return; } $this->hr(); $this->out("Plugin Name: {$plugin}"); $this->out("Plugin Directory: {$this->path}{$pluginPath}"); $this->hr(); $looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y'); if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') { $verbose = $this->in(__('Do you want verbose output?'), array('y', 'n'), 'n'); App::uses('Folder', 'Utility'); $Folder = new Folder($this->path . $pluginPath); $directories = array('Model' . DS . 'Behavior', 'Controller' . DS . 'Component', 'View' . DS . 'Helper'); foreach ($directories as $directory) { $Folder->create($this->path . $pluginPath . DS . $directory); } if (strtolower($verbose) == 'y' || strtolower($verbose) == 'yes') { foreach ($Folder->messages() as $message) { $this->out($message); } } $errors = $Folder->errors(); if (!empty($errors)) { return false; } $controllerFileName = $pluginPath . 'AppController.php'; $out = "<?php\n\n"; $out .= "class {$plugin}AppController extends AppController {\n\n"; $out .= "}\n\n"; $out .= "?>"; $this->createFile($this->path . $pluginPath . DS . 'Controller' . DS . $controllerFileName, $out); $modelFileName = $pluginPath . 'AppModel.php'; $out = "<?php\n\n"; $out .= "class {$plugin}AppModel extends AppModel {\n\n"; $out .= "}\n\n"; $out .= "?>"; $this->createFile($this->path . $pluginPath . DS . 'Model' . DS . $modelFileName, $out); $out = "<?php\n"; $out .= "\$pluginContainer = ClassRegistry::getObject('PluginContainer');\n"; $plugin_id = Inflector::underscore($pluginPath); $out .= "\$pluginContainer->installed('{$plugin_id}','0.1');\n"; $out .= "\n\n"; $this->createFile($this->path . $pluginPath . DS . 'init.php', $out); $out = "<?php\n"; $out .= "\tclass HomeController extends {$plugin}AppController {\n"; $out .= "\tpublic \$uses = array('Issue');\n"; $out .= "\tpublic function index() {\n"; $out .= "\t\t\$this->set('count',\$this->Issue->find('count'));\n"; $out .= "\t}\n"; $out .= "}\n"; $out .= "\n"; $this->createFile($this->path . $pluginPath . DS . 'Controller/HomeController.php', $out); $out = ""; $out .= "Hello CandyCane {$plugin} Plugin.<br/>"; $out .= "You have <?php echo \$count ?> of issues."; $out .= "\n\n"; $this->createFile($this->path . $pluginPath . DS . 'View' . DS . 'Home' . DS . 'index.ctp', $out); $this->hr(); $this->out(sprintf(__("Created: %s in %s"), $plugin, $this->path . $pluginPath)); $this->hr(); } return true; }
/** * Bake the plugin, create directories and files * * @params $plugin name of the plugin in CamelCased format * @access public * @return bool */ public function bake($plugin) { $pluginPath = Inflector::underscore($plugin); $pathOptions = App::path('plugins'); if (count($pathOptions) > 1) { $this->findPath($pathOptions); } $this->hr(); $this->out(__("<info>Plugin Name:</info> %s", $plugin)); $this->out(__("<info>Plugin Directory:</info> %s", $this->path . $pluginPath)); $this->hr(); $looksGood = $this->in(__('Look okay?'), array('y', 'n', 'q'), 'y'); if (strtolower($looksGood) == 'y') { $Folder = new Folder($this->path . $pluginPath); $directories = array('config' . DS . 'schema', 'models' . DS . 'behaviors', 'models' . DS . 'datasources', 'console' . DS . 'shells' . DS . 'tasks', 'controllers' . DS . 'components', 'libs', 'views' . DS . 'helpers', 'tests' . DS . 'cases' . DS . 'components', 'tests' . DS . 'cases' . DS . 'helpers', 'tests' . DS . 'cases' . DS . 'behaviors', 'tests' . DS . 'cases' . DS . 'controllers', 'tests' . DS . 'cases' . DS . 'models', 'tests' . DS . 'groups', 'tests' . DS . 'fixtures', 'vendors', 'webroot'); foreach ($directories as $directory) { $dirPath = $this->path . $pluginPath . DS . $directory; $Folder->create($dirPath); $File = new File($dirPath . DS . 'empty', true); } foreach ($Folder->messages() as $message) { $this->out($message, 1, Shell::VERBOSE); } $errors = $Folder->errors(); if (!empty($errors)) { return false; } $controllerFileName = $pluginPath . '_app_controller.php'; $out = "<?php\n\n"; $out .= "class {$plugin}AppController extends AppController {\n\n"; $out .= "}\n\n"; $out .= "?>"; $this->createFile($this->path . $pluginPath . DS . $controllerFileName, $out); $modelFileName = $pluginPath . '_app_model.php'; $out = "<?php\n\n"; $out .= "class {$plugin}AppModel extends AppModel {\n\n"; $out .= "}\n\n"; $out .= "?>"; $this->createFile($this->path . $pluginPath . DS . $modelFileName, $out); $this->hr(); $this->out(__('<success>Created:</success> %s in %s', $plugin, $this->path . $pluginPath), 2); } return true; }
/** * Delete plugin * * @param $alias * * @return array|bool */ public static function delete($alias) { $folder = new Folder(APP . 'Plugin' . DS . $alias); if ($folder->delete()) { return true; } else { return $folder->errors(); } }