/** * 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; }