Exemplo n.º 1
0
 public function moveFiles($id, $key, $deleteOrginal = false)
 {
     $e = self::$_extensions;
     if ($e['per_id'][$id]['status'] === 'uploaded') {
         require_once 'CRM/Utils/File.php';
         CRM_Utils_File::copyDir($e['per_id'][$id]['path'], $this->extDir . DIRECTORY_SEPARATOR . $e['per_id'][$id]['type'] . DIRECTORY_SEPARATOR . $e['per_id'][$id]['key']);
         if ($deleteOrginal) {
             $this->deleteFiles($id, $key);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Move $fromDir to $toDir, replacing/deleting any
  * pre-existing content.
  *
  * @param string $fromDir
  *   The directory which should be moved.
  * @param string $toDir
  *   The new location of the directory.
  * @param bool $verbose
  *
  * @return bool
  *   TRUE on success
  */
 public static function replaceDir($fromDir, $toDir, $verbose = FALSE)
 {
     if (is_dir($toDir)) {
         if (!self::cleanDir($toDir, TRUE, $verbose)) {
             return FALSE;
         }
     }
     // return rename($fromDir, $toDir); CRM-11987, https://bugs.php.net/bug.php?id=54097
     CRM_Utils_File::copyDir($fromDir, $toDir);
     if (!CRM_Utils_File::cleanDir($fromDir, TRUE, FALSE)) {
         CRM_Core_Session::setStatus(ts('Failed to clean temp dir: %1', array(1 => $fromDir)), '', 'alert');
         return FALSE;
     }
     return TRUE;
 }
Exemplo n.º 3
0
 public function copyDir($source, $destination)
 {
     $dir = opendir($source);
     @mkdir($destination);
     while (FALSE !== ($file = readdir($dir))) {
         if ($file != '.' && $file != '..') {
             if (is_dir($source . DIRECTORY_SEPARATOR . $file)) {
                 CRM_Utils_File::copyDir($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
             } else {
                 copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
             }
         }
     }
     closedir($dir);
 }
 public function installFiles()
 {
     $config = CRM_Core_Config::singleton();
     $zip = new ZipArchive();
     $res = $zip->open($this->tmpFile);
     if ($res === TRUE) {
         $zipSubDir = CRM_Utils_Zip::guessBasedir($zip, $this->key);
         if ($zipSubDir === FALSE) {
             CRM_Core_Session::setStatus(ts('Unable to extract the extension: bad directory structure') . '<br/>');
             return FALSE;
         }
         $path = $config->extensionsDir . DIRECTORY_SEPARATOR . 'tmp';
         $extractedZipPath = $path . DIRECTORY_SEPARATOR . $zipSubDir;
         if (is_dir($extractedZipPath)) {
             if (!CRM_Utils_File::cleanDir($extractedZipPath, TRUE, FALSE)) {
                 CRM_Core_Session::setStatus(ts('Unable to extract the extension: %1 cannot be cleared', array(1 => $extractedZipPath)) . '<br/>');
                 return FALSE;
             }
         }
         if (!$zip->extractTo($path)) {
             CRM_Core_Session::setStatus(ts('Unable to extract the extension to %1.', array(1 => $path)) . '<br/>');
             return FALSE;
         }
         $zip->close();
     } else {
         CRM_Core_Session::setStatus('Unable to extract the extension.');
         return FALSE;
     }
     $filename = $extractedZipPath . DIRECTORY_SEPARATOR . 'info.xml';
     if (!is_readable($filename)) {
         CRM_Core_Session::setStatus(ts('Failed reading data from %1 during installation', array(1 => $filename)) . '<br/>');
         return FALSE;
     }
     $newxml = file_get_contents($filename);
     if (empty($newxml)) {
         CRM_Core_Session::setStatus(ts('Failed reading data from %1 during installation', array(1 => $filename)) . '<br/>');
         return FALSE;
     }
     $check = new CRM_Core_Extensions_Extension($this->key . ".newversion");
     $check->readXMLInfo($newxml);
     if ($check->version != $this->version) {
         CRM_Core_Error::fatal('Cannot install - there are differences between extdir XML file and archive XML file!');
     }
     // Why is this a copy instead of a move?
     CRM_Utils_File::copyDir($extractedZipPath, $config->extensionsDir . DIRECTORY_SEPARATOR . $this->key);
     if (!CRM_Utils_File::cleanDir($extractedZipPath, TRUE, FALSE)) {
         CRM_Core_Session::setStatus(ts('Failed to clean temp dir: %1', array(1 => $extractedZipPath)) . '<br/>');
     }
     return TRUE;
 }