public function index()
 {
     if (strpos(UrlHelper::build('/', true), 'dev') == false) {
         $this->set('files', []);
         $this->set('stats', []);
         return;
     }
     $files = [];
     $dev_folders_to_check = ['../src', '../plugins', '../webroot', '../config'];
     $prod_folders_to_check = ['../../production/src', '../../production/plugins', '../../production/webroot', '../../production/config'];
     $d = 0;
     foreach ($dev_folders_to_check as $folder) {
         $dir = new Folder($folder);
         $tree = $dir->tree(null, ['.htaccess', 'error_log'])[1];
         sort($tree);
         foreach ($tree as $entry) {
             $file = new File($entry);
             preg_match('/.*development(.*)/', $entry, $filename);
             $filename = $filename[1];
             $files[$filename]['dev_date'] = Time::createFromTimestamp(round($file->lastChange() / 60) * 60);
             $d++;
         }
     }
     $ud = $d;
     // Unique Files Dev. Will Subtract 1 for each file match.
     $nd = 0;
     // Newer Files Dev.
     $p = 0;
     $up = 0;
     $np = 0;
     foreach ($prod_folders_to_check as $folder) {
         $dir = new Folder($folder);
         $tree = $dir->tree(null, ['.htaccess', 'error_log'])[1];
         sort($tree);
         foreach ($tree as $entry) {
             $file = new File($entry);
             preg_match('/.*production(.*)/', $entry, $filename);
             $filename = $filename[1];
             $date = Time::createFromTimestamp(round($file->lastChange() / 60) * 60);
             $files[$filename]['prod_date'] = $date;
             if (isset($files[$filename]['dev_date'])) {
                 $ud--;
                 if ($date < $files[$filename]['dev_date']) {
                     $nd++;
                 } elseif ($date > $files[$filename]['dev_date']) {
                     $np++;
                 } else {
                     unset($files[$filename]);
                 }
             } else {
                 $up++;
             }
             $p++;
         }
     }
     $stats = ['files_dev' => $d, 'files_prod' => $p, 'unique_dev' => $ud, 'unique_prod' => $up, 'newer_dev' => $nd, 'newer_prod' => $np];
     $this->set('files', $files);
     $this->set('stats', $stats);
 }
예제 #2
0
 /**
  * Recursively adds all the files in a directory to the test suite.
  *
  * @param string $directory The directory subtree to add tests from.
  * @return void
  */
 public function addTestDirectoryRecursive($directory = '.')
 {
     $Folder = new Folder($directory);
     $files = $Folder->tree(null, true, 'files');
     foreach ($files as $file) {
         if (substr($file, -4) === '.php') {
             $this->addTestFile($file);
         }
     }
 }
예제 #3
0
 /**
  * Updates the catalog file from the given po file
  *
  * @return void
  */
 public function updateFromCatalog()
 {
     $domain = $this->params['domain'];
     #$localePaths = App::path('Locale');
     $localePath = ROOT . '/src/Locale/';
     $catalogFile = $localePath . $domain . '.pot';
     if (!file_exists($catalogFile)) {
         return $this->abort(sprintf('Catalog File %s not found.', $catalogFile));
     }
     $poFiles = [];
     $folder = new Folder($localePath);
     $tree = $folder->tree();
     foreach ($tree[1] as $file) {
         $basename = basename($file);
         if ($domain . '.po' === $basename) {
             $poFiles[] = $file;
         }
     }
     if (empty($poFiles)) {
         return $this->abort('I could not find any matching po files in the given locale path (%s) for the domain (%s)', $localePath, $domain);
     }
     if (!$this->params['overwrite']) {
         $this->out('I will update the following .po files and their corresponding .mo file with the keys from catalog: ' . $catalogFile);
         foreach ($poFiles as $poFile) {
             $this->out('    - ' . $poFile);
         }
         $response = $this->in('Would you like to continue?', ['y', 'n'], 'n');
         if ($response !== 'y') {
             return $this->abort('Aborted');
         }
     }
     foreach ($poFiles as $poFile) {
         $catalogEntries = Translations::fromPoFile($catalogFile);
         $moFile = str_replace('.po', '.mo', $poFile);
         $translationEntries = Translations::fromPoFile($poFile);
         $newTranslationEntries = $catalogEntries->mergeWith($translationEntries, Merge::REFERENCES_THEIRS);
         $newTranslationEntries->deleteHeaders();
         foreach ($translationEntries->getHeaders() as $key => $value) {
             $newTranslationEntries->setHeader($key, $value);
         }
         if ($this->params['strip-references']) {
             foreach ($newTranslationEntries as $translation) {
                 $translation->deleteReferences();
             }
         }
         $newTranslationEntries->toPoFile($poFile);
         $newTranslationEntries->toMoFile($moFile);
         $this->out('Updated ' . $poFile);
         $this->out('Updated ' . $moFile);
     }
 }
 /**
  * return all existing "folders" in repository as [<pageId> => '/<pageId>/']
  */
 public function getExistingFolders()
 {
     $folder = new Folder($this->getFolder());
     $paths = $folder->tree(null, false, 'dir');
     $folders = [];
     foreach ($paths as $path) {
         $path = str_replace($this->getFolder(), '', $path);
         $title = '/' . $path . '/';
         $title = str_replace('//', '/', $title);
         $folders[$path] = $title;
     }
     unset($folders['.']);
     asort($folders);
     return $folders;
 }
 /**
  * Recursively checks if the given directory (and its content) can be deleted.
  *
  * This method automatically registers an error message if validation fails.
  *
  * @param string $path Directory to check
  * @return bool
  */
 protected function _canBeDeleted($path)
 {
     $type = $this->_plugin->isTheme ? 'theme' : 'plugin';
     if (!file_exists($path) || !is_dir($path)) {
         $this->err(__d('installer', "{0} directory was not found: {1}", $type == 'plugin' ? __d('installer', "Plugin's") : __d('installer', "Theme's"), $path));
         return false;
     }
     $folder = new Folder($path);
     $folderContent = $folder->tree();
     $notWritable = [];
     foreach ($folderContent as $foldersOrFiles) {
         foreach ($foldersOrFiles as $element) {
             if (!is_writable($element)) {
                 $notWritable[] = $element;
             }
         }
     }
     if (!empty($notWritable)) {
         $this->err(__d('installer', "{0} files or directories cannot be removed from your server, please check write permissions of:", $type == 'plugin' ? __d('installer', "Some plugin's") : __d('installer', "Some theme's")));
         foreach ($notWritable as $path) {
             $this->err(__d('installer', '  - {0}', [$path]));
         }
         return false;
     }
     return true;
 }
예제 #6
0
 /**
  * testFolderTreeWithHiddenFiles method
  *
  * @return void
  */
 public function testFolderTreeWithHiddenFiles()
 {
     $this->skipIf(!is_writable(TMP), 'Can\'t test Folder::tree with hidden files unless the tmp folder is writable.');
     $path = TMP . 'tests' . DS;
     $Folder = new Folder($path . 'folder_tree_hidden', true, 0777);
     mkdir($Folder->path . DS . '.svn', 0777, true);
     touch($Folder->path . DS . '.svn/InHiddenFolder.php');
     mkdir($Folder->path . DS . '.svn/inhiddenfolder');
     touch($Folder->path . DS . '.svn/inhiddenfolder/NestedInHiddenFolder.php');
     touch($Folder->path . DS . 'not_hidden.txt');
     touch($Folder->path . DS . '.hidden.txt');
     mkdir($Folder->path . DS . 'visible_folder/.git', 0777, true);
     $expected = [[$Folder->path, $Folder->path . DS . 'visible_folder'], [$Folder->path . DS . 'not_hidden.txt']];
     $result = $Folder->tree(null, true);
     $this->assertEquals($expected, $result);
     $result = $Folder->tree(null, ['.']);
     $this->assertEquals($expected, $result);
     $expected = [[$Folder->path, $Folder->path . DS . 'visible_folder', $Folder->path . DS . 'visible_folder' . DS . '.git', $Folder->path . DS . '.svn', $Folder->path . DS . '.svn' . DS . 'inhiddenfolder'], [$Folder->path . DS . 'not_hidden.txt', $Folder->path . DS . '.hidden.txt', $Folder->path . DS . '.svn' . DS . 'inhiddenfolder' . DS . 'NestedInHiddenFolder.php', $Folder->path . DS . '.svn' . DS . 'InHiddenFolder.php']];
     $result = $Folder->tree(null, false);
     sort($result[0]);
     sort($expected[0]);
     sort($result[1]);
     sort($expected[1]);
     $this->assertEquals($expected, $result);
     $Folder->delete();
 }
예제 #7
0
 /**
  * Edit method
  *
  * @param string|null $id Projet id.
  * @return void Redirects on successful edit, renders view otherwise.
  * @throws \Cake\Network\Exception\NotFoundException When record not found.
  */
 public function edit($id = null)
 {
     $projet = $this->Projets->get($id, ['contain' => []]);
     $region = $this->Projets->Regions->get($projet->region_id);
     if ($this->request->is(['patch', 'post', 'put'])) {
         $projet = $this->Projets->patchEntity($projet, $this->request->data);
         if ($this->Projets->save($projet)) {
             $this->Flash->success(__('Les changements ont bien été enregistré !'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('Impossible d\'enregistrer les changements. Veuillez réesseyer !'));
         }
     }
     $folder = new Folder(ROOT . '/plugins/Admin/webroot/img/projets/');
     $foldersTree = $folder->tree();
     $foldersImages = $foldersTree[0];
     $folders = [];
     foreach ($foldersImages as $folderImg) {
         $parts = explode('/', $folderImg);
         $folderName = end($parts);
         if ($folderName != '') {
             array_push($folders, $folderName);
         }
     }
     $regions = $this->Projets->Regions->find();
     $this->set(compact('projet', 'regions'));
     $this->set('_serialize', ['projet']);
     $this->set('region', $region);
     $this->set('_serialize', ['region']);
     $this->set('data', ['title' => __("Modifier un projet"), 'folders' => $folders]);
     $this->set(compact('data'));
     $this->set('menu', ['panelSelected' => null, 'projetSelected' => 'menuActifDash', 'regionSelected' => null, 'pageSelected' => null, 'userSelected' => null, 'gestionSelected' => null]);
 }