示例#1
0
 /**
  * testDelete method
  *
  * @return void
  */
 public function testDelete()
 {
     $path = TMP . 'tests' . DS . 'folder_delete_test';
     mkdir($path, 0777, true);
     touch($path . DS . 'file_1');
     mkdir($path . DS . 'level_1_1');
     touch($path . DS . 'level_1_1/file_1_1');
     mkdir($path . DS . 'level_1_1/level_2_1');
     touch($path . DS . 'level_1_1/level_2_1/file_2_1');
     touch($path . DS . 'level_1_1/level_2_1/file_2_2');
     mkdir($path . DS . 'level_1_1/level_2_2');
     $Folder = new Folder($path, true);
     $return = $Folder->delete();
     $this->assertTrue($return);
     $messages = $Folder->messages();
     $errors = $Folder->errors();
     $this->assertEquals([], $errors);
     $expected = [$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);
 }
 public function sync($id = null)
 {
     $folder = new Folder();
     $folders_to_copy = ['f1' => ['dev' => '../src', 'prod' => '../../production/src'], 'f2' => ['dev' => '../plugins', 'prod' => '../../production/plugins'], 'f3' => ['dev' => '../webroot', 'prod' => '../../production/webroot'], 'f4' => ['dev' => '../config', 'prod' => '../../production/config']];
     $pass = 0;
     $fail = 0;
     foreach ($folders_to_copy as $ftc) {
         $p = new Folder($ftc['prod']);
         $d = new Folder($ftc['dev']);
         if ($folder->copy(['to' => $p->pwd(), 'from' => $d->pwd(), 'scheme' => Folder::MERGE])) {
             $pass++;
         } else {
             $fail++;
         }
     }
     if ($fail == 0) {
         $this->Flash->success(__('Production updated successfully.'));
     } else {
         $errors = '';
         foreach ($folder->errors() as $error) {
             $errors .= ' : ' . $error;
         }
         $this->Flash->error(__('Unable to update {0} folders on production. Errors' . $errors, $fail));
     }
     return $this->redirect($this->referer());
 }
示例#3
0
 /**
  * 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('Plugin');
     if (count($pathOptions) > 1) {
         $this->findPath($pathOptions);
     }
     $this->hr();
     $this->out(sprintf("<info>Plugin Name:</info> %s", $plugin));
     $this->out(sprintf("<info>Plugin Directory:</info> %s", $this->path . $plugin));
     $this->hr();
     $classBase = 'src';
     $looksGood = $this->in('Look okay?', ['y', 'n', 'q'], 'y');
     if (strtolower($looksGood) === 'y') {
         $Folder = new Folder($this->path . $plugin);
         $directories = ['config', $classBase . DS . 'Model' . DS . 'Behavior', $classBase . DS . 'Model' . DS . 'Table', $classBase . DS . 'Model' . DS . 'Entity', $classBase . DS . 'Shell' . DS . 'Task', $classBase . DS . 'Controller' . DS . 'Component', $classBase . DS . 'View' . DS . 'Helper', $classBase . DS . 'Template', 'tests' . DS . 'TestCase' . DS . 'Controller' . DS . 'Component', 'tests' . DS . 'TestCase' . DS . 'View' . DS . 'Helper', 'tests' . DS . 'TestCase' . DS . 'Model' . DS . 'Behavior', 'tests' . DS . 'Fixture', '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 = 'AppController.php';
         $out = "<?php\n\n";
         $out .= "namespace {$plugin}\\Controller;\n\n";
         $out .= "use App\\Controller\\AppController as BaseController;\n\n";
         $out .= "class AppController extends BaseController {\n\n";
         $out .= "}\n";
         $this->createFile($this->path . $plugin . DS . $classBase . DS . 'Controller' . DS . $controllerFileName, $out);
         $emptyFile = $this->path . 'empty';
         $this->_deleteEmptyFile($emptyFile);
         $hasAutoloader = $this->_modifyAutoloader($plugin, $this->path);
         $this->_generateRoutes($plugin, $this->path);
         $this->_modifyBootstrap($plugin, $hasAutoloader);
         $this->_generatePhpunitXml($plugin, $this->path);
         $this->_generateTestBootstrap($plugin, $this->path);
         $this->hr();
         $this->out(sprintf('<success>Created:</success> %s in %s', $plugin, $this->path . $plugin), 2);
     }
     return true;
 }