Exemple #1
0
 /**
  * Test recursive copying of directories
  *
  *
  */
 public function testRCopy()
 {
     $name = $this->_get_rand_name();
     $source_dir = dirname(dirname(__FILE__)) . '/model/samples/repo1';
     $target_dir = MODX_CORE_PATH . 'cache/repoman/' . $name;
     Repoman::rcopy($source_dir, $target_dir, array());
     $this->assertTrue(file_exists($target_dir . '/elements') && is_dir($target_dir . '/elements'), 'elements directory must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/plugins') && is_dir($target_dir . '/elements/plugins'), 'elements/plugins directory must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/snippets') && is_dir($target_dir . '/elements/snippets'), 'elements/snippets directory must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/templates') && is_dir($target_dir . '/elements/templates'), 'elements/templates directory must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/tvs') && is_dir($target_dir . '/elements/tvs'), 'elements/tvs directory must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/chunks/MyChunk.html'), 'elements/chunks/MyChunk.html file must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/plugins/MyPlugin.php'), 'elements/plugins/MyPlugin.php file must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/snippets/MySnippet.php'), 'elements/snippets/MySnippet.php file must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/templates/MyTemplate.html'), 'elements/templates/MyTemplate.html file must exist');
     $this->assertTrue(file_exists($target_dir . '/elements/tvs/myTV.php'), 'elements/tvs/myTV.php file must exist');
     Repoman::rrmdir($target_dir);
 }
Exemple #2
0
 /**
  * Recursively copy files and directories.
  *
  * @param string $source      dir
  * @param string $destination dir
  * @param array  $omissions   full path to any files to omit (optional)
  *
  * @throws Exception
  * @return bool
  */
 public static function rcopy($source, $destination, $omissions = array())
 {
     global $modx;
     // for logging
     $source = rtrim($source, '/');
     $destination = rtrim($destination, '/');
     if (is_dir($source)) {
         if (!file_exists($destination)) {
             if (mkdir($destination, 0777) === false) {
                 throw new Exception('Could not create directory ' . $destination);
             }
         }
         $directory = dir($source);
         while (false !== ($readdirectory = $directory->read())) {
             if ($readdirectory == '.' || $readdirectory == '..') {
                 continue;
             }
             $PathDir = $source . '/' . $readdirectory;
             if (in_array($PathDir, $omissions)) {
                 $modx->log(modX::LOG_LEVEL_INFO, "Omitting path: " . $PathDir);
                 continue;
                 // skip
             }
             if (is_dir($PathDir)) {
                 Repoman::rcopy($PathDir, $destination . '/' . $readdirectory, $omissions);
                 continue;
             } else {
                 copy($PathDir, $destination . '/' . $readdirectory);
             }
         }
         $directory->close();
     } else {
         print "{$source} is a file\n";
         return copy($source, $destination);
     }
 }