/**
  *
  * @access
  * @author "Lionel Lecaque, <*****@*****.**>"
  * @param unknown $ext
  * @return boolean
  */
 public function shield($ext, $destination)
 {
     $extFolder = ROOT_PATH . DIRECTORY_SEPARATOR . $ext;
     if (is_file($extFolder . '/htaccess.1')) {
         throw new taoUpdate_models_classes_UpdateException('Previous lock, htaccess.1 still exits, delete it in ' . $extFolder);
     }
     helpers_File::copy($extFolder . '/.htaccess', $extFolder . '/htaccess.1', true, false);
     if (is_file($extFolder . '/htaccess.1') && is_writable($extFolder . '/.htaccess')) {
         file_put_contents($extFolder . '/.htaccess', "Options +FollowSymLinks\n" . "<IfModule mod_rewrite.c>\n" . "RewriteEngine On\n" . "RewriteCond %{REQUEST_URI} !/views/  [NC]\n" . "RewriteRule ^.*\$ " . ROOT_URL . $destination . " [L]\n" . "</IfModule>");
         return true;
     } else {
         throw new taoUpdate_models_classes_UpdateException('.htaccess is not writtable in ' . $extFolder);
     }
 }
Пример #2
0
 public function import($id, $directoryPath)
 {
     $directory = $this->getDirectoryById($id);
     if (file_exists($directory->getPath())) {
         if (tao_helpers_File::isDirEmpty($directory->getPath())) {
             common_Logger::d('Directory already found but content is empty');
             helpers_File::copy($directoryPath, $directory->getPath(), true);
         } else {
             if (tao_helpers_File::isIdentical($directory->getPath(), $directoryPath)) {
                 common_Logger::d('Directory already found but content is identical');
             } else {
                 throw new common_Exception('Duplicate dir ' . $id . ' with different content');
             }
         }
     } else {
         mkdir($directory->getPath(), 0700, true);
         helpers_File::copy($directoryPath, $directory->getPath(), true);
     }
 }
Пример #3
0
 /**
  * Ask the repository to deal with a file located in $filePath. It will return
  * you a reference on Versioned File.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  string filePath The path to the file you want the repository to deal with.
  * @param  string label A label for the created file Resource.
  * @param  callable $createFileName A function that generates unique file name during spawn file
  * @return core_kernel_versioning_File
  * @since 2.4
  */
 public function spawnFile($filePath, $label = '', callable $createFileName = null)
 {
     $returnValue = null;
     if (!$createFileName) {
         $createFileName = [__CLASS__, 'createFileName'];
     }
     $fileInfo = new SplFileInfo($filePath);
     $relativePath = str_replace([$this->getPath(), $fileInfo->getFilename(), dirname($filePath)], '', $fileInfo->getPathname());
     $fileName = $createFileName($fileInfo->getFilename());
     $destination = $this->getPath() . $relativePath . $fileName;
     $source = $filePath;
     if (helpers_File::copy($source, $destination, true, false)) {
         if ($fileInfo->isDir()) {
             $returnValue = $this->createFile('', $relativePath . $fileName);
         } else {
             $returnValue = $this->createFile($fileName);
         }
         if (!empty($label)) {
             $returnValue->setLabel($label);
         }
     }
     return $returnValue;
 }
 /**
  * Retrieve a file from a given $url and copy it to its final $destination.
  * 
  * @param string $url The URL to be dereferenced.
  * @param string $destination The destination of the retrieved file, on the file system.
  * @return boolean|string false If an error occurs during the retrieval/copy process, or the final destination name if it succeeds.
  */
 public static function retrieveFile($url, $destination)
 {
     $fileName = basename($url);
     //check file name compatibility:
     //e.g. if a file with a common name (e.g. car.jpg, house.png, sound.mp3) already exists in the destination folder
     while (file_exists($destination . $fileName)) {
         $lastDot = strrpos($fileName, '.');
         $fileName = substr($fileName, 0, $lastDot) . '_' . substr($fileName, $lastDot);
     }
     // Since the file has not been downloaded yet, start downloading it using cUrl
     // Only if the resource is external, else we copy it
     if (!preg_match('@^' . ROOT_URL . '@', $url)) {
         common_Logger::d('Downloading ' . $url);
         helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::NO_TIMEOUT);
         $fp = fopen($destination . $fileName, 'w+');
         $curlHandler = curl_init();
         curl_setopt($curlHandler, CURLOPT_URL, $url);
         curl_setopt($curlHandler, CURLOPT_FILE, $fp);
         curl_setopt($curlHandler, CURLOPT_TIMEOUT, 50);
         curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, true);
         //if there is an http auth on the local domain, it's mandatory to auth with curl
         if (USE_HTTP_AUTH) {
             $addAuth = false;
             $domains = array('localhost', '127.0.0.1', ROOT_URL);
             foreach ($domains as $domain) {
                 if (preg_match("/" . preg_quote($domain, '/') . "/", $url)) {
                     $addAuth = true;
                 }
             }
             if ($addAuth) {
                 curl_setopt($curlHandler, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                 curl_setopt($curlHandler, CURLOPT_USERPWD, USE_HTTP_USER . ":" . USE_HTTP_PASS);
             }
         }
         curl_exec($curlHandler);
         $httpCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
         $success = $httpCode == 200;
         curl_close($curlHandler);
         fclose($fp);
         helpers_TimeOutHelper::reset();
     } else {
         $path = tao_helpers_File::getPathFromUrl($url);
         common_Logger::d('Copying ' . $path);
         $success = helpers_File::copy($path, $destination . $fileName);
     }
     if ($success == false) {
         common_Logger::w('Unable to retrieve ' . $url);
         return false;
     } else {
         return $destination . $fileName;
     }
 }
Пример #5
0
 /**
  * Import specific source from the repository to the given target at the given revision
  *
  * @access public
  * @author Cédric Alfonsi, <*****@*****.**>
  * @param  Repository vcs
  * @param  string src
  * @param  string target
  * @param  string message
  * @param  array options
  * @return core_kernel_file_File
  */
 public function import(core_kernel_versioning_Repository $vcs, $src, $target, $message = "", $options = array())
 {
     $returnValue = null;
     //Does not work in the current version of php (try later) https://bugs.php.net/bug.php?id=60293
     //$returnValue = svn_import($src, $target, true);
     $startTime = helpers_Time::getMicroTime();
     $saveResource = isset($options['saveResource']) && $options['saveResource'] ? true : false;
     if (!$vcs->authenticate()) {
         throw new core_kernel_versioning_exception_Exception('Authentication failed on fileSource ' . $vcs->getUri());
     }
     $repositoryUrl = $vcs->getUrl();
     $relativePath = substr($target, strlen($repositoryUrl));
     $absolutePath = $vcs->getPath() . $relativePath;
     /*
     // The resource could already exist, this is not a problem
     //check if the resource already exist
     if(helpers_File::resourceExists($absolutePath)){
     	throw new core_kernel_versioning_exception_ResourceAlreadyExistsException('The folder ('.$absolutePath.') already exists in the repository ('.$vcs->getPath().')');
     }
     // Same thing here
     //check if the file already exist
     else if(file_exists($absolutePath)){
     	throw new common_exception_FileAlreadyExists($absolutePath);
     }
     */
     //Copy the src folder to the target destination
     helpers_File::copy($src, $absolutePath);
     // Create the importFolder
     $importFolder = $vcs->createFile('', $relativePath);
     //			//Get status of the imported folder
     //			$importFolderStatus = $importFolder->getStatus(array('SHOW_UPDATES'=>false));
     //			$importFolderYetCommited = true;
     //			if($importFolderStatus == VERSIONING_FILE_STATUS_ADDED || $importFolderStatus == VERSIONING_FILE_STATUS_UNVERSIONED){
     //				$importFolderYetCommited = false;
     //			}
     //
     //			//If the import folder has been yet commited, commit its content
     //			if($importFolderYetCommited){
     //				$filesToCommit = tao_helpers_File::scandir($importFolder->getAbsolutePath());
     //				$pathsFilesToCommit = array();
     //				foreach($filesToCommit as $fileToCommit){
     //					$pathFileToCommit = $fileToCommit->getAbsolutePath();
     //					$pathsFilesToCommit[] = $pathFileToCommit;
     //					//Add content of the folder if it is not versioned or partially not versioned
     //					if(!core_kernel_versioning_FileProxy::add($importFolder, $pathFileToCommit, true, true)){
     //						throw new core_kernel_versioning_exception_Exception('unable to import the folder ('.$src.') to the destination ('.$target.'). The add step encountered a problem');
     //					}
     //				}
     //				//Commit all the files in one commit operation
     //				if(!core_kernel_versioning_FileProxy::commit($VersionedUnitFolderInstance, $pathsFilesToCommit)){
     //					throw new core_kernel_versioning_exception_Exception('unable to import the folder ('.$src.') to the destination ('.$target.'). The commit step encountered a problem');
     //				}
     //			}
     //			//Else commit itself
     //			else{
     //				//Add the folder
     //				if(!$importFolder->add(true, true)){
     //					throw new core_kernel_versioning_exception_Exception('unable to import the folder ('.$src.') to the destination ('.$target.'). The add step encountered a problem');
     //				}
     //				//And commit it
     //				if(!$importFolder->commit($message, true)){
     //					throw new core_kernel_versioning_exception_Exception('unable to import the folder ('.$src.') to the destination ('.$target.'). The commit step encountered a problem');
     //				}
     //			}
     //Add the folder
     if (!$importFolder->add(true, true)) {
         throw new core_kernel_versioning_exception_Exception('unable to import the folder (' . $src . ') to the destination (' . $target . '). The add step encountered a problem');
     }
     //And commit it
     if (!$importFolder->commit($message, true)) {
         throw new core_kernel_versioning_exception_Exception('unable to import the folder (' . $src . ') to the destination (' . $target . '). The commit step encountered a problem');
     }
     //Delete the resource if the developer does not want to keep a reference in the onthology
     if ($saveResource) {
         $returnValue = $importFolder;
     } else {
         $resourceToDelete = new core_kernel_classes_Resource($importFolder->getUri());
         $resourceToDelete->delete();
     }
     $endTime = helpers_Time::getMicroTime();
     common_Logger::i("svn_import (" . $src . ' -> ' . $target . ') -> ' . ($endTime - $startTime) . 's');
     return $returnValue;
 }
Пример #6
0
 /**
  * Ask the repository to deal with a file located in $filePath. It will return
  * you a reference on Versioned File.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  string filePath The path to the file you want the repository to deal with.
  * @param  string label A label for the created file Resource.
  * @return core_kernel_versioning_File
  * @since 2.4
  */
 public function spawnFile($filePath, $label = '')
 {
     $returnValue = null;
     $fileInfo = new SplFileInfo($filePath);
     $fileName = self::createFileName($fileInfo->getFilename());
     $destination = $this->getPath() . $fileName;
     $source = $filePath;
     if (helpers_File::copy($source, $destination, true, false)) {
         if ($fileInfo->isDir()) {
             $returnValue = $this->createFile('', $fileName);
         } else {
             $returnValue = $this->createFile($fileName);
         }
         if (!empty($label)) {
             $returnValue->setLabel($label);
         }
     }
     return $returnValue;
 }
 /**
  * 
  * @access 
  * @author "Lionel Lecaque, <*****@*****.**>"
  * @param string $release
  * @param string $fileName
  * @param string $downloadFolder
  * @throws taoUpdate_models_classes_UpdateException
  * @return string
  */
 private function copyLocalVersion($release, $fileName, $downloadFolder)
 {
     common_Logger::i('Problem getting release from distant server will use local file instead');
     $srcFolder = BASE_DATA . self::RELEASES_LOCAL_FOLDER;
     if (is_file($srcFolder . $fileName)) {
         helpers_File::copy($srcFolder . $fileName, $downloadFolder . $fileName, false);
         $path = $downloadFolder . $fileName;
     } else {
         throw new taoUpdate_models_classes_UpdateException('Could not find a release with file ' . $fileName);
     }
     return $path;
 }