Ejemplo n.º 1
0
 /**
  * Find all defined callbacks in the app or other plugins
  *
  * @param undefined $cached
  * @return void
  * @access public
  */
 public function load()
 {
     $cached = Cache::read('_plugin_callbacks_', '_cake_models_');
     if ($cached !== false) {
         $this->settings = $cached;
         return $cached;
     }
     App::import('Folder');
     $Folder = new Folder($this->path . 'plugins');
     $folders = current($Folder->ls());
     $files = array();
     foreach ($folders as $folder) {
         if ($Folder->cd($this->path . 'models' . DS . 'callbacks')) {
             $files = $Folder->findRecursive('([a-z_]+)_' . $folder . '.php');
         }
         $files = array_flip($files);
         foreach ($folders as $_folder) {
             if ($Folder->cd($this->path . 'plugins' . DS . $_folder . DS . 'models' . DS . 'callbacks')) {
                 $files = array_merge($files, array_flip($Folder->findRecursive('([a-z_]+)_' . $folder . '.php')));
             }
         }
         foreach (array_keys($files) as $k => $file) {
             if (!preg_match_all('/models\\/callbacks\\/([a-z_]+)_' . $folder . '\\.php/i', $file, $matches)) {
                 continue;
             }
             $plugin = current($matches[1]);
             if (empty($plugin)) {
                 $plugin = 'app';
             }
             $callbackName = Inflector::camelize(sprintf('%s_%s', $plugin, $folder));
             $this->settings[$folder][$plugin] = $callbackName;
         }
     }
     Cache::write('_plugin_callbacks_', $this->settings, '_cake_models_');
 }
Ejemplo n.º 2
0
 function read($dir = null, $recursive = false)
 {
     $notes = array();
     $path = CORE_PATH . APP_PATH . $dir;
     $folder = new Folder(APP_PATH . $dir);
     $fold = $recursive ? $folder->findRecursive('.*\\.php') : $folder->find('.*\\.php');
     foreach ($fold as $file) {
         $file = $recursive ? $file : $path . $file;
         $file_path = r(CORE_PATH . APP_PATH, '', $file);
         $handle = new File($file_path);
         $content = $handle->read();
         $lines = explode(PHP_EOL, $content);
         //$lines = file($file);
         $ln = 1;
         if (!empty($lines)) {
             foreach ($lines as $line) {
                 if ((is_null($this->type) || $this->type == 'TODO') && preg_match("/[#\\*\\/\\/]\\s*TODO\\s*(.*)/", $line, $match)) {
                     $this->notes[$file_path]['TODO'][$ln] = $match[1];
                 }
                 if ((is_null($this->type) || $this->type == 'OPTIMIZE') && preg_match("/[#\\*\\/\\/]\\s*OPTIMIZE|OPTIMISE\\s*(.*)/", $line, $match)) {
                     $this->notes[$file_path]['OPTIMIZE'][$ln] = $match[1];
                 }
                 if ((is_null($this->type) || $this->type == 'FIXME') && preg_match("/[#\\*\\/\\/]\\s*FIXME|BUG\\s*(.*)/", $line, $match)) {
                     $this->notes[$file_path]['FIXME'][$ln] = $match[1];
                 }
                 $ln++;
             }
         }
     }
     return $this->notes;
 }
 function create()
 {
     $dir = new Folder(APP);
     $files = $dir->findRecursive('.*');
     $data_array = array();
     foreach ($files as $file) {
         $file_parts = pathinfo($file);
         if (isset($file_parts['extension']) && ($file_parts['extension'] == "php" || $file_parts['extension'] == "ctp")) {
             $data = file_get_contents($file);
             $pattern = "~(__\\('|__\\(\")(.*?)(\\'\\)|\",|\\',|\"\\)|\" \\)|\\' \\))~";
             preg_match_all($pattern, $data, $matches);
             $data_array = array_filter(array_merge($data_array, $matches[2]));
         }
     }
     $data_array = array_unique($data_array);
     pr($data_array);
     $filename = 'adefault.po';
     $file = new File(APP . "/Locale" . DS . $filename);
     foreach ($data_array as $string) {
         $file->write('msgid "' . $string . '"' . "\n");
         $file->write('msgstr "' . $string . '"' . "\n\n");
         echo $string;
     }
     $file->close();
     die;
 }
Ejemplo n.º 4
0
 /**
  * Truncates all tables and loads fixtures into db
  *
  * @return void
  * @access public
  */
 function main()
 {
     if (!empty($this->args)) {
         if ($this->args[0] == 'chmod') {
             return $this->chmod();
         }
         $fixtures = $this->args;
         foreach ($fixtures as $i => $fixture) {
             $fixtures[$i] = APP . 'tests/fixtures/' . $fixture . '_fixture.php';
         }
     } else {
         App::import('Folder');
         $Folder = new Folder(APP . 'tests/fixtures');
         $fixtures = $Folder->findRecursive('.+_fixture\\.php');
     }
     $db = ConnectionManager::getDataSource('default');
     $records = 0;
     foreach ($fixtures as $path) {
         require_once $path;
         $name = str_replace('_fixture.php', '', basename($path));
         $class = Inflector::camelize($name) . 'Fixture';
         $Fixture =& new $class($db);
         $this->out('-> Truncating table "' . $Fixture->table . '"');
         $db->truncate($Fixture->table);
         $Fixture->insert($db);
         $fixtureRecords = count($Fixture->records);
         $records += $fixtureRecords;
         $this->out('-> Inserting ' . $fixtureRecords . ' records for "' . $Fixture->table . '"');
     }
     $this->out(sprintf('-> Done inserting %d records for %d tables', $records, count($fixtures)));
 }
Ejemplo n.º 5
0
 public function main()
 {
     $App = new Folder(APP);
     $r = $App->findRecursive('.*\\.php');
     $this->out("Checking *.php in " . APP);
     $folders = array();
     foreach ($r as $file) {
         $error = '';
         $action = '';
         $c = file_get_contents($file);
         if (preg_match('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', $c)) {
             $error = 'leading';
         }
         if (preg_match('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', $c)) {
             $error = 'trailing';
         }
         if (!empty($error)) {
             $this->report[$error][0]++;
             $this->out('');
             $this->out('contains ' . $error . ' whitespaces: ' . $this->shortPath($file));
             if (!$this->autoCorrectAll) {
                 $dirname = dirname($file);
                 if (in_array($dirname, $folders)) {
                     $action = 'y';
                 }
                 while (empty($action)) {
                     //TODO: [r]!
                     $action = $this->in(__('Remove? [y]/[n], [a] for all in this folder, [r] for all below, [*] for all files(!), [q] to quit'), array('y', 'n', 'r', 'a', 'q', '*'), 'q');
                 }
             } else {
                 $action = 'y';
             }
             if ($action == '*') {
                 $action = 'y';
                 $this->autoCorrectAll = true;
             } elseif ($action == 'a') {
                 $action = 'y';
                 $folders[] = $dirname;
                 $this->out('All: ' . $dirname);
             }
             if ($action == 'q') {
                 die('Abort... Done');
             } elseif ($action == 'y') {
                 if ($error == 'leading') {
                     $res = preg_replace('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', '<?php', $c);
                 } else {
                     //trailing
                     $res = preg_replace('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', '?>', $c);
                 }
                 file_put_contents($file, $res);
                 $this->report[$error][1]++;
                 $this->out('fixed ' . $error . ' whitespaces: ' . $this->shortPath($file));
             }
         }
     }
     # report
     $this->out('--------');
     $this->out('found ' . $this->report['leading'][0] . ' leading, ' . $this->report['trailing'][0] . ' trailing ws');
     $this->out('fixed ' . $this->report['leading'][1] . ' leading, ' . $this->report['trailing'][1] . ' trailing ws');
 }
Ejemplo n.º 6
0
 /**
  * Main worker
  *
  * @return void
  */
 public function main()
 {
     if (empty($this->args)) {
         $this->error("Require at least one file path");
         die;
     }
     foreach ($this->args as $input) {
         $path = $this->getPath($input);
         if (empty($path)) {
             $this->error("Unable to find {$input}");
             die;
         }
         if (is_file($path)) {
             $files = array($path);
         }
         if (is_dir($path)) {
             $dir = new Folder($path);
             $files = $dir->findRecursive('.*\\.php$');
         }
         if (empty($files)) {
             $this->error("Invalid file type {$path}");
             die;
         }
         foreach ($files as $file) {
             $this->out($file);
             PhpTidy::file($file);
         }
     }
 }
 function upload()
 {
     $directory = $this->getNextParam(null, 'path');
     $container = $this->getNextParam(null, 'container');
     if (empty($directory) || empty($container)) {
         $this->errorAndExit('Directory and Container required');
     }
     $Folder = new Folder($directory);
     if ($this->params['recursive']) {
         $files = $Folder->findRecursive();
     } else {
         $single_files = $Folder->find();
         $files = array();
         foreach ($single_files as $file) {
             $files[] = $Folder->pwd() . DS . $file;
         }
     }
     $this->ProgressBar->start(count($files));
     foreach ($files as $file) {
         CloudFiles::upload($file, $container);
         $this->ProgressBar->next();
     }
     $this->out();
     $this->out("Finished.");
 }
Ejemplo n.º 8
0
 public function execute()
 {
     // I18nProfile class: http://stackoverflow.com/questions/8433686/is-there-a-php-library-for-parsing-gettext-po-pot-files
     App::import('Lib', 'I18nJs.PoParser');
     $dir = new Folder(APP . 'Locale');
     $locales = $dir->read();
     foreach ($locales[0] as $localeDir) {
         $msgids = array();
         $language = $localeDir;
         $localeDir = new Folder(APP . 'Locale' . DS . $localeDir);
         $files = $localeDir->findRecursive('i18n_js.*\\.po');
         // Loop over PO i18n_js PO files
         foreach ($files as $file) {
             $file = new File($file);
             // Get language
             if (preg_match('%Locale/(.*?)/LC_MESSAGES%', $file->path, $regs)) {
                 $language = $regs[1];
             } else {
                 // todo return
                 $this->out(__d('i18n_js', '<error>Unable to determine language of PO file:</error>') . $file->path);
                 return;
             }
             // Get context, domain
             $context = '';
             if (strpos($file->name(), '.')) {
                 $context = explode('.', $file->name());
                 $context = $context[1];
             }
             // Parse PO file
             $poparser = new \Sepia\PoParser();
             $translations = $poparser->parse($file->path);
             foreach ($translations as $key => $translation) {
                 if (empty($key)) {
                     continue;
                 }
                 if (is_array($translation['msgid'])) {
                     $translation['msgid'] = implode('', $translation['msgid']);
                 }
                 if (is_array($translation['msgstr'])) {
                     $translation['msgstr'] = implode('', $translation['msgstr']);
                 }
                 $msgids[$context][$translation['msgid']] = $translation['msgstr'];
             }
         }
         if (empty($msgids)) {
             continue;
         }
         // Write JS file
         $outputFile = new File(WWW_ROOT . 'js' . DS . 'Locale' . DS . 'i18n_js.' . $language . '.js', true);
         $data = "I18nJs.locale = { ";
         $data .= "'pluralFormula': function (\$n) { return Number((\$n != 1)); }, ";
         $data .= "'strings': " . json_encode($msgids, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT) . " };";
         if ($outputFile->write($data)) {
             $this->out(__d('i18n_js', '<info>%s created</info>', $outputFile->path));
         } else {
             $this->out(__d('i18n_js', '<error>Unable to write: %s</error>', $outputFile->path));
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * Collects the files to scan and generate build files for.
  *
  * @param array $paths 
  */
 protected function _collectFiles($paths)
 {
     foreach ($paths as $path) {
         $Folder = new Folder($path);
         $files = $Folder->findRecursive('.*\\.(ctp|thtml|inc|tpl)', true);
         $this->_files = array_merge($this->_files, $files);
     }
 }
Ejemplo n.º 10
0
 /**
  * testRunAllTests method
  *
  * @return void
  * @access public
  */
 function testRunAllTests()
 {
     $folder = new Folder($this->Sut->_getTestsPath());
     $extension = str_replace('.', '\\.', TestManager::getExtension('test'));
     $out = $folder->findRecursive('.*' . $extension);
     $reporter = new CakeHtmlReporter();
     $list = TestManager::runAllTests($reporter, true);
     $this->assertEqual(count($out), count($list));
 }
Ejemplo n.º 11
0
 /**
  * Recursive Read a path and return files and folders not in the excluded Folder list
  *
  * @param string $path The path you wish to read.
  * @return array
  **/
 public function fileList($path)
 {
     $this->_Folder->cd($path);
     $filePattern = $this->fileRegExp . '\\.' . implode('|', $this->allowedExtensions);
     $contents = $this->_Folder->findRecursive($filePattern);
     $this->_filterFolders($contents);
     $this->_filterFiles($contents);
     return $contents;
 }
 public function getPrototypes()
 {
     $searchdirs['App'] = APP . 'View';
     $searchdirs['Basic'] = CakePlugin::path('Muffin');
     foreach (CakePlugin::loaded() as $plugin) {
         if ($plugin != 'Muffin') {
             $searchdirs[$plugin] = CakePlugin::path($plugin) . 'View';
         }
     }
     $configs = array();
     foreach ($searchdirs as $plugin => $searchdir) {
         $dir = new Folder($searchdir, false);
         if ($files = $dir->findRecursive('config.xml')) {
             $configs = Hash::merge($configs, array($plugin => $files));
         }
     }
     $prototypes = array();
     foreach ($configs as $plugin => $configFiles) {
         $i = 0;
         foreach ($configFiles as $configFile) {
             $xml = Xml::build($configFile);
             $items = $xml->xpath('menu/item');
             if (!is_array($items) || empty($items)) {
                 continue;
             }
             foreach ($items as $item) {
                 $item = Xml::toArray($item);
                 if (empty($item['item']['@label'])) {
                     continue;
                 }
                 if (!isset($item['item']['@id']) || empty($item['item']['@id'])) {
                     $id = ucfirst(Inflector::variable($item['item']['@label']));
                 } else {
                     $id = $item['item']['@id'];
                 }
                 $fields = array();
                 foreach ($item['item']['field'] as $key => $field) {
                     foreach ($field as $name => $value) {
                         $name = str_replace('@', '', $name);
                         $fields[$key][$name] = $value;
                     }
                 }
                 $prototypes[$plugin][$i]['Link']['id'] = $id;
                 $prototypes[$plugin][$i]['Link']['priority'] = !empty($item['item']['@priority']) ? $item['item']['@priority'] : '10';
                 $prototypes[$plugin][$i]['Link']['model'] = !empty($item['item']['@model']) ? $item['item']['@model'] : '';
                 $prototypes[$plugin][$i]['Link']['label'] = $item['item']['@label'];
                 $prototypes[$plugin][$i]['Field'] = $fields;
                 $i++;
             }
         }
     }
     foreach ($prototypes as $plugin => $section) {
         $prototypes[$plugin] = Hash::sort($section, '{n}.Link.priority', 'asc');
     }
     return $prototypes;
 }
 /**
  * NoCrossContaminationGroupTest method
  *
  * @access public
  * @return void
  */
 function NoCrossContaminationGroupTest()
 {
     App::import('Core', 'Folder');
     $Folder = new Folder(CORE_TEST_CASES);
     foreach ($Folder->findRecursive('.*\\.test\\.php', true) as $file) {
         if (in_array(basename($file), $this->blacklist)) {
             continue;
         }
         TestManager::addTestFile($this, $file);
     }
 }
Ejemplo n.º 14
0
 function tests()
 {
     $path = TESTS . 'cases';
     $Folder = new Folder($path);
     $cases = $Folder->findRecursive('.*\\.test\\.php');
     foreach ($cases as $i => $case) {
         $case = str_replace($path, '', $case);
         $case = str_replace('.test.php', '', $case);
         $cases[$i] = trim($case, DS);
     }
     return array('cases' => $cases);
 }
Ejemplo n.º 15
0
 /**
  * Much like main() except files are modified.  Be sure to have 
  * backups or use version control.
  *
  * @return void
  */
 function trim()
 {
     $siteRoot = new Folder(ROOT);
     $r = $siteRoot->findRecursive('.*\\.php');
     $this->out("Checking *.php in " . ROOT);
     foreach ($r as $file) {
         $c = file_get_contents($file);
         if (preg_match('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', $c) || preg_match('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', $c)) {
             $this->out('trimming' . $this->shortPath($file));
             $c = preg_replace('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', '<?php', $c);
             $c = preg_replace('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', '?>', $c);
             file_put_contents($file, $c);
         }
     }
 }
Ejemplo n.º 16
0
 function main()
 {
     $App = new Folder(APP);
     $r = $App->findRecursive('.*\\.php');
     $this->out("Checking *.php in " . APP);
     foreach ($r as $file) {
         $c = file_get_contents($file);
         if (preg_match('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', $c)) {
             $this->out('!!!contains leading whitespaces: ' . $this->shortPath($file));
         }
         if (preg_match('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', $c)) {
             $this->out('!!!contains trailing whitespaces: ' . $this->shortPath($file));
         }
     }
 }
Ejemplo n.º 17
0
 /**
  * Generates filesystem and model maps
  *
  * @access protected
  * @return void
  */
 function _generateMaps()
 {
     $fsFiles = $this->_Folder->findRecursive();
     $results = $this->_Model->find('all');
     $fsMap = array();
     $dbMap = array();
     foreach ($fsFiles as $value) {
         $File = new File($value);
         $fsMap[] = array('file' => $File->pwd(), 'checksum' => $File->md5(true));
     }
     foreach ($results as $result) {
         $dbMap[] = array('id' => $result[$this->_Model->name]['id'], 'file' => $this->_baseDirectory . $result[$this->_Model->name]['dirname'] . DS . $result[$this->_Model->name]['basename'], 'checksum' => $result[$this->_Model->name]['checksum']);
     }
     return array($fsMap, $dbMap);
 }
Ejemplo n.º 18
0
 /**
  * undocumented function
  *
  * @param string $Model
  * @param string $config
  * @return void
  */
 public function setup(&$Model, $config = array())
 {
     if (is_string($config)) {
         $config = array('default' => $config);
     }
     $this->_set($config);
     if (!($this->cached = Cache::read($this->name))) {
         App::import('Folder');
         $Folder = new Folder(APP . 'plugins' . DS . 'localized' . DS . 'plugins' . DS . 'localized' . DS . 'libs');
         $this->cached = $Folder->findRecursive('([a-z]{2})_validation\\.php');
         foreach ($this->cached as $k => $cached) {
             preg_match('/([a-z]{2})_validation\\.php/', $cached, $match);
             $this->cached[$k] = $match[1];
         }
         Cache::write($this->name, $this->cached);
     }
 }
Ejemplo n.º 19
0
 /**
  * Main worker
  */
 public function main()
 {
     foreach ($this->basePaths() as $path) {
         $this->out("Fixtures in {$path}");
         $F = new Folder($path);
         $files = $F->findRecursive('.*Fixture.php');
         if (empty($files)) {
             $this->out("  no fixutres to cleanup");
             continue;
         }
         foreach ($files as $file) {
             $this->out("  {$file}");
             $this->processFixture($file);
         }
     }
     $this->out('done');
 }
 /**
  * Custom function for migrating from old file browser (kcfinder) to new one
  * 
  * 1. upload all files inside of the webroot/upload folder (including the upload folder) to s3
  * 2. run this migrate function
  * 3. check the /file_storage/file_storage/browser page (thumbnails should be showing up correctly now)
  * 4. delete the files from the server
  */
 public function migrate()
 {
     $replacement = $directory = ROOT . DS . SITE_DIR . DS . 'Locale' . DS . 'View' . DS . 'webroot';
     $directory = $replacement . DS . 'upload';
     App::uses('Folder', 'Utility');
     App::uses('File', 'Utility');
     $dir = new Folder($directory);
     $files = $dir->findRecursive();
     foreach ($files as $file) {
         $file = new File($file);
         $info = $file->info();
         $model = $this->_detectModelByFileType($info['mime']);
         if (!empty($model)) {
             $data['FileStorage']['model'] = $model;
             $data['FileStorage']['filename'] = $info['basename'];
             $data['FileStorage']['filesize'] = $info['filesize'];
             $data['FileStorage']['mime_type'] = $info['mime'];
             $data['FileStorage']['extension'] = $info['extension'];
             $data['FileStorage']['path'] = '/' . str_replace('sites/', '', SITE_DIR) . str_replace($replacement, '', $info['dirname']) . '/';
             $data['FileStorage']['adapter'] = 'S3Storage';
             $data['FileStorage']['creator_id'] = $int = intval(filter_var($data['FileStorage']['path'], FILTER_SANITIZE_NUMBER_INT));
             $data['FileStorage']['modifier_id'] = $int;
             $data['FileStorage']['created'] = date('Y-m-d H:i:s', $file->lastChange());
             $data['FileStorage']['modified'] = date('Y-m-d H:i:s');
             if ($duplicate = $this->FileStorage->find('first', array('conditions' => array('FileStorage.filename' => $data['FileStorage']['filename'])))) {
                 debug('Duplicate : ' . $data['FileStorage']['filename']);
                 unset($data);
                 continue;
             }
             $this->FileStorage->create();
             if ($this->FileStorage->save($data, array('callbacks' => false))) {
                 debug('Saved: ' . $data['FileStorage']['filename']);
                 unset($data);
                 continue;
             } else {
                 debug($data);
                 exit;
             }
         }
         $file->close();
     }
     $this->render(false);
 }
 /**
  * Much like main() except files are modified. Be sure to have
  * backups or use version control.
  *
  * @return void
  */
 public function trim()
 {
     $path = APP;
     if (!empty($this->params['path']) && strpos($this->params['path'], '/') === 0) {
         $path = $this->params['path'];
     } elseif (!empty($this->params['path'])) {
         $path .= $this->params['path'];
     }
     $folder = new Folder($path);
     $r = $folder->findRecursive('.*\\.php');
     $this->out("Checking *.php in " . $path);
     foreach ($r as $file) {
         $c = file_get_contents($file);
         if (preg_match('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', $c) || preg_match('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', $c)) {
             $this->out('trimming' . $this->shortPath($file));
             $c = preg_replace('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', '<?php', $c);
             $c = preg_replace('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', '?>', $c);
             file_put_contents($file, $c);
         }
     }
 }
Ejemplo n.º 22
0
 /**
  * Truncates all tables and loads fixtures into db
  *
  * @return void
  * @access public
  */
 function main()
 {
     if (!empty($this->args) && $this->args[0] != 'all') {
         $fixtures = $this->args;
         foreach ($fixtures as $i => $fixture) {
             $fixtures[$i] = APP . 'tests/fixtures/' . $fixture . '_fixture.php';
         }
     } elseif (!empty($this->args) && $this->args[0] == 'all') {
         App::import('Folder');
         $Folder = new Folder(APP . 'tests/fixtures');
         $fixtures = $Folder->findRecursive('.+_fixture\\.php');
     } else {
         $this->out('Usage: cake fixtures [ all | <table-name-singluar> ]');
         return;
     }
     $datasource = 'default';
     if (isset($this->params['datasource'])) {
         $datasource = $this->params['datasource'];
     }
     $list = ConnectionManager::enumConnectionObjects();
     if (!isset($list[$datasource])) {
         $this->error("Data Source", "Non-existent data source '{$datasource}'");
     }
     $db = ConnectionManager::getDataSource($datasource);
     $records = 0;
     foreach ($fixtures as $path) {
         require_once $path;
         $name = str_replace('_fixture.php', '', basename($path));
         $class = Inflector::camelize($name) . 'Fixture';
         $Fixture =& new $class($db);
         $this->out('-> Truncating table "' . $Fixture->table . '"');
         $db->truncate($Fixture->table);
         $Fixture->insert($db);
         $fixtureRecords = count($Fixture->records);
         $records += $fixtureRecords;
         $this->out('-> Inserting ' . $fixtureRecords . ' records for "' . $Fixture->table . '"');
     }
     $this->out(sprintf('-> Done inserting %d records for %d tables', $records, count($fixtures)));
 }
Ejemplo n.º 23
0
 /**
  * Main execution methpd
  *
  * @access public
  * @return void
  */
 function execute()
 {
     if (isset($this->params['model'])) {
         $this->model = $this->params['model'];
     } else {
         $this->model = $this->in('Model', null, 'Media.Attachment');
     }
     $this->_Model = ClassRegistry::init($this->model);
     if (!isset($this->_Model->Behaviors->Generator)) {
         $this->error("Model `{$this->model}` has the `Generator` behavior not attached to it.");
     }
     $settings = $this->_Model->Behaviors->Generator->settings[$this->_Model->alias];
     if (!($this->source = array_shift($this->args))) {
         $this->source = $this->in('Source directory', null, $settings['baseDirectory']);
     }
     $message = 'Regex (matches against the basenames of the files) for source inclusion:';
     $pattern = $this->in($message, null, '.*');
     $this->out();
     $this->out(sprintf('%-25s: %s', 'Base', $this->shortPath($settings['baseDirectory'])));
     $this->out(sprintf('%-25s: %s (%s)', 'Source', $this->shortPath($this->source), $pattern));
     $this->out(sprintf('%-25s: %s', 'Destination', $this->shortPath($settings['filterDirectory'])));
     $this->out(sprintf('%-25s: %s', 'Overwrite existing', $settings['overwrite'] ? 'yes' : 'no'));
     $this->out(sprintf('%-25s: %s', 'Create directories', $settings['createDirectory'] ? 'yes' : 'no'));
     if ($this->in('Looks OK?', 'y,n', 'y') == 'n') {
         return false;
     }
     $this->out();
     $this->out('Making');
     $this->hr();
     $Folder = new Folder($this->source);
     $files = $Folder->findRecursive($pattern);
     $this->progress(count($files));
     foreach ($files as $key => $file) {
         $this->progress($key, $this->shortPath($file));
         $this->_Model->make($file);
     }
     $this->out();
 }
Ejemplo n.º 24
0
 /**
  * Search files that may contain translatable strings
  *
  * @return void
  */
 protected function _searchFiles()
 {
     $pattern = false;
     if (!empty($this->_exclude)) {
         $exclude = array();
         foreach ($this->_exclude as $e) {
             if (DS !== '\\' && $e[0] !== DS) {
                 $e = DS . $e;
             }
             $exclude[] = preg_quote($e, '/');
         }
         $pattern = '/' . implode('|', $exclude) . '/';
     }
     foreach ($this->_paths as $path) {
         $Folder = new Folder($path);
         $files = $Folder->findRecursive('.*\\.(php|ctp|thtml|inc|tpl)', true);
         if (!empty($pattern)) {
             foreach ($files as $i => $file) {
                 if (preg_match($pattern, $file)) {
                     unset($files[$i]);
                 }
             }
             $files = array_values($files);
         }
         $this->_files = array_merge($this->_files, $files);
     }
 }
Ejemplo n.º 25
0
 /**
  * (Interactively) maps source files to destinations
  *
  * @param string $path Path to search for source files
  * @access protected
  * @return array
  */
 function _map($path)
 {
     $include = '.*[\\/\\].*\\.[a-z0-9]{2,3}$';
     $directories = array('.htaccess', '.DS_Store', 'media', '.git', '.svn', 'simpletest', 'empty');
     $extensions = array('db', 'htm', 'html', 'txt', 'php', 'ctp');
     $exclude = '.*[/\\\\](' . implode('|', $directories) . ').*$';
     $exclude .= '|.*[/\\\\].*\\.(' . implode('|', $extensions) . ')$';
     if (!empty($this->_exclude)) {
         $exclude = '|.*[/\\\\](' . implode('|', $this->_exclude) . ').*$';
     }
     $Folder = new Folder($path);
     $files = $Folder->findRecursive($include);
     foreach ($files as $file) {
         if (preg_match('#' . $exclude . '#', $file)) {
             continue;
         }
         $search[] = '/' . preg_quote($Folder->pwd(), '/') . '/';
         $search[] = '/(' . implode('|', Media::short()) . ')' . preg_quote(DS, '/') . '/';
         $fragment = preg_replace($search, null, $file);
         $mapped = array($file => MEDIA_STATIC . Media::short($file) . DS . $fragment);
         while (in_array(current($mapped), $this->_map) && $mapped) {
             $mapped = $this->_handleCollision($mapped);
         }
         while (file_exists(current($mapped)) && $mapped) {
             $this->out($this->shortPath(current($mapped)) . ' already exists.');
             $answer = $this->in('Would you like to [r]ename or [s]kip?', 'r,s', 's');
             if ($answer == 's') {
                 $mapped = array();
             } else {
                 $mapped = array(key($mapped) => $this->_rename(current($mapped)));
             }
         }
         if ($mapped) {
             $this->_map[key($mapped)] = current($mapped);
         }
     }
 }
Ejemplo n.º 26
0
Archivo: Mi.php Proyecto: razzman/mi
 /**
  * files method
  *
  * @param mixed $path
  * @param array $excludePaths
  * @param string $pattern
  * @return void
  * @access public
  */
 public function files($path = null, $excludePaths = array(), $pattern = '.*php')
 {
     if (is_array($path)) {
         extract(am(array('path' => null), $path));
     }
     $folder = new Folder($path);
     $return = $folder->findRecursive($pattern);
     foreach ((array) $excludePaths as $excludePath) {
         if (!is_dir($path . $excludePath)) {
             continue;
         }
         $folder = new Folder($path . $excludePath);
         $return = array_diff($return, $folder->findRecursive($pattern));
     }
     return $return;
 }
Ejemplo n.º 27
0
 /**
  * Main execution methpd
  *
  * @access public
  * @return void
  */
 function execute()
 {
     $this->interactive = count($this->args) != 2;
     $this->force = isset($this->params['force']);
     $this->source = array_shift($this->args);
     $this->destination = array_shift($this->args);
     if (!isset($this->source)) {
         $this->source = $this->in('Source File/Directory', null, MEDIA . 'static' . DS);
     }
     if (is_dir($this->source)) {
         $this->source = Folder::slashTerm($this->source);
     }
     if (!isset($this->destination)) {
         $this->destination = $this->in('Destination Directory', null, MEDIA . 'filter' . DS);
     }
     $this->destination = Folder::slashTerm($this->destination);
     if ($this->force) {
         $this->_overwrite = $this->_createDirectories = true;
     }
     if (isset($this->params['version'])) {
         $this->version = $this->params['version'];
     }
     $this->out();
     $this->out(sprintf('%-25s: %s', 'Source', $this->shortPath($this->source)));
     $this->out(sprintf('%-25s: %s', 'Destination', $this->shortPath($this->destination)));
     $this->out(sprintf('%-25s: %s', 'Overwrite existing', $this->_overwrite ? 'yes' : 'no'));
     $this->out(sprintf('%-25s: %s', 'Create directories', $this->_createDirectories ? 'yes' : 'no'));
     if ($this->in('Looks OK?', 'y,n', 'y') == 'n') {
         return false;
     }
     $this->out();
     $this->out('Making');
     $this->hr();
     if (is_file($this->source)) {
         $files = array($this->source);
     } else {
         $Folder = new Folder($this->source);
         $files = $Folder->findRecursive();
     }
     $this->progress(count($files));
     foreach ($files as $key => $file) {
         $this->progress($key, $this->shortPath($file));
         $this->_make($file);
     }
     $this->out();
 }
Ejemplo n.º 28
0
 /**
  * testFindRecursive method
  *
  * @return void
  */
 public function testFindRecursive()
 {
     $Folder = new Folder();
     $Folder->cd(CAKE);
     $result = $Folder->findRecursive('(config|paths)\\.php');
     $expected = array(CAKE . 'Config' . DS . 'config.php');
     $this->assertSame(array_diff($expected, $result), array());
     $this->assertSame(array_diff($expected, $result), array());
     $result = $Folder->findRecursive('(config|paths)\\.php', true);
     $expected = array(CAKE . 'Config' . DS . 'config.php');
     $this->assertSame($expected, $result);
     $Folder->cd(TMP);
     $Folder->create($Folder->pwd() . DS . 'testme');
     $Folder->cd('testme');
     $File = new File($Folder->pwd() . DS . 'paths.php');
     $File->create();
     $Folder->cd(TMP . 'sessions');
     $result = $Folder->findRecursive('paths\\.php');
     $expected = array();
     $this->assertSame($expected, $result);
     $Folder->cd(TMP . 'testme');
     $File = new File($Folder->pwd() . DS . 'my.php');
     $File->create();
     $Folder->cd($Folder->pwd() . '/../..');
     $result = $Folder->findRecursive('(paths|my)\\.php');
     $expected = array(TMP . 'testme' . DS . 'my.php', TMP . 'testme' . DS . 'paths.php');
     $this->assertSame(array_diff($expected, $result), array());
     $this->assertSame(array_diff($expected, $result), array());
     $result = $Folder->findRecursive('(paths|my)\\.php', true);
     $expected = array(TMP . 'testme' . DS . 'my.php', TMP . 'testme' . DS . 'paths.php');
     $this->assertSame($expected, $result);
     $Folder->cd(CAKE . 'Config');
     $Folder->cd(TMP);
     $Folder->delete($Folder->pwd() . DS . 'testme');
     $File->delete();
 }
Ejemplo n.º 29
0
 /**
  * Search files that may contain translateable strings
  *
  * @return void
  * @access private
  */
 function __searchFiles()
 {
     foreach ($this->__paths as $path) {
         $Folder = new Folder($path);
         $files = $Folder->findRecursive('.*\\.(php|ctp|thtml|inc|tpl)', true);
         $this->__files = array_merge($this->__files, $files);
     }
 }
Ejemplo n.º 30
0
 /**
  * Move files and folders to their new homes
  *
  * Moves folders containing files which cannot necessarily be auto-detected (libs and templates)
  * and then looks for all php files except vendors, and moves them to where Cake 2.0 expects
  * to find them.
  *
  * @return void
  */
 public function locations()
 {
     if (!empty($this->params['custom'])) {
         return;
     }
     $cwd = getcwd();
     if (!empty($this->params['plugin'])) {
         chdir(CakePlugin::path($this->params['plugin']));
     }
     if (is_dir('plugins') && !empty($this->params['plugin'])) {
         $Folder = new Folder('plugins');
         list($plugins) = $Folder->read();
         foreach ($plugins as $plugin) {
             chdir($cwd . DS . 'plugins' . DS . $plugin);
             $this->out(__d('cake_console', 'Upgrading locations for plugin %s', $plugin));
             $this->locations();
         }
         $this->_files = array();
         chdir($cwd);
         $this->out('Upgrading locations for app directory');
     }
     $moves = array('locale' => 'Locale', 'config' => 'Config', 'Config' . DS . 'schema' => 'Config' . DS . 'Schema', 'libs' => 'Lib', 'tests' => 'Test', 'views' => 'View', 'models' => 'Model', 'Model' . DS . 'behaviors' => 'Model' . DS . 'Behavior', 'Model' . DS . 'datasources' => 'Model' . DS . 'Datasource', 'Test' . DS . 'cases' => 'Test' . DS . 'Case', 'Test' . DS . 'fixtures' => 'Test' . DS . 'Fixture', 'vendors' . DS . 'shells' . DS . 'templates' => 'Console' . DS . 'Templates');
     foreach ($moves as $old => $new) {
         if (is_dir($old)) {
             $this->out(__d('cake_console', 'Moving %s to %s', $old, $new));
             if (!$this->params['dry-run']) {
                 $this->_move($old, $new);
             }
         }
     }
     $this->_moveViewFiles();
     $this->_moveAppClasses();
     $sourceDirs = array('.' => array('recursive' => false), 'Console', 'controllers', 'Controller', 'Lib' => array('checkFolder' => false), 'models', 'Model', 'tests', 'Test' => array('regex' => '@class (\\S*Test) extends CakeTestCase@'), 'Test/fixtures', 'Test/Fixture', 'views', 'View', 'vendors/shells');
     $defaultOptions = array('recursive' => true, 'checkFolder' => true, 'regex' => '@class (\\S*) .*(\\s|\\v)*{@i');
     foreach ($sourceDirs as $dir => $options) {
         if (is_numeric($dir)) {
             $dir = $options;
             $options = array();
         }
         $options = array_merge($defaultOptions, $options);
         $this->_movePhpFiles($dir, $options);
         if (!$options['recursive']) {
             continue;
         }
         $Folder = new Folder($dir);
         $files = $Folder->findRecursive();
         if (count($files) === 0 && file_exists($folderPath = $Folder->pwd())) {
             $path = str_replace(APP, DS, $folderPath);
             $this->_delete($folderPath);
             $this->out(__d('cake_console', 'Removing empty folder %s', $path));
         }
     }
 }