예제 #1
0
 protected function GetWorkingDirectory($strCheckoutCommand = null)
 {
     $this->strWorkingDirectory = sprintf('%s/upload-u_%d-l_%s-p_%d', __TMP_PATH__, QApplication::GetUserId(), $this->objLanguage->LanguageCode, $this->objProject->ProjectId);
     $this->CleanWorkingDirectory();
     if (!$this instanceof NarroMercurialSourcePanel) {
         mkdir($this->strWorkingDirectory);
     }
     $strCommand = sprintf($strCheckoutCommand, escapeshellarg($this->txtRepository->Text), escapeshellarg($this->strWorkingDirectory));
     NarroLogger::LogInfo(sprintf('Running "%s"', $strCommand));
     $strProcLogFile = __TMP_PATH__ . '/' . $this->objProject->ProjectId . '-' . $this->objLanguage->LanguageCode . '-vcs.log';
     if (file_exists($strProcLogFile) && is_writable($strProcLogFile)) {
         unlink($strProcLogFile);
     }
     chdir(__TMP_PATH__);
     $mixProcess = proc_open("{$strCommand}", array(1 => array("file", $strProcLogFile, 'a'), 2 => array("file", $strProcLogFile, 'a')), $foo);
     $status = proc_get_status($mixProcess);
     while ($status['running']) {
         $status = proc_get_status($mixProcess);
     }
     proc_close($mixProcess);
     if (!file_exists($this->strWorkingDirectory)) {
         throw new Exception(sprintf('The working directory "%s" does not exist, probably the checkout command failed', $this->strWorkingDirectory));
     }
     chmod($this->strWorkingDirectory, 0777);
     if (file_exists($strProcLogFile)) {
         NarroLogger::LogInfo(file_get_contents($strProcLogFile));
     }
     NarroUtils::RecursiveDelete($this->strWorkingDirectory . '/.hg');
     foreach (NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, '.svn') as $strSvnDir) {
         NarroUtils::RecursiveDelete($strSvnDir);
     }
     $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode);
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode . '-' . $this->objLanguage->CountryCode);
     }
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode . '_' . $this->objLanguage->CountryCode);
     }
     NarroUtils::RecursiveChmod($this->strWorkingDirectory);
     if (is_array($arrSearchResult) && count($arrSearchResult) == 1) {
         NarroLogger::LogWarn(sprintf('Path changed from "%s" to "%s" because a directory named "%s" was found deeper in the given path.', $this->strWorkingDirectory, $arrSearchResult[0], $this->objLanguage->LanguageCode));
         $this->strWorkingDirectory = $arrSearchResult[0];
     }
     if ($this->chkCopyFilesToDefaultDirectory->Checked) {
         if (file_exists(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode)) {
             NarroUtils::RecursiveDelete(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode . '/*');
         } else {
             mkdir(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode, 0777, true);
         }
         NarroUtils::RecursiveCopy($this->strWorkingDirectory, __IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode);
         NarroUtils::RecursiveChmod(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode);
     }
     return $this->strWorkingDirectory;
 }
예제 #2
0
 protected function GetWorkingDirectory()
 {
     if (!file_exists($this->fileSource->File)) {
         throw new Exception('You have to upload a file');
     }
     $this->strWorkingDirectory = sprintf('%s/upload-u_%d-l_%s-p_%d', __TMP_PATH__, QApplication::GetUserId(), $this->objLanguage->LanguageCode, $this->objProject->ProjectId);
     $this->CleanWorkingDirectory();
     mkdir($this->strWorkingDirectory);
     chmod($this->strWorkingDirectory, 0777);
     switch (strtolower(pathinfo($this->fileSource->File, PATHINFO_EXTENSION))) {
         case 'zip':
         case 'xpi':
             NarroLogger::LogInfo(sprintf('Trying to uncompress %s', $this->fileSource->FileName));
             $objZipFile = new ZipArchive();
             $intErrCode = $objZipFile->open($this->fileSource->File);
             if ($intErrCode === TRUE) {
                 $objZipFile->extractTo($this->strWorkingDirectory);
                 $objZipFile->close();
                 NarroLogger::LogInfo(sprintf('Sucessfully uncompressed %s.', $this->fileSource->FileName));
             } else {
                 switch ($intErrCode) {
                     case ZIPARCHIVE::ER_NOZIP:
                         $strError = 'Not a zip archive';
                         break;
                     default:
                         $strError = 'Error code: ' . $intErrCode;
                 }
                 $this->fileSource->File = '';
                 throw new Exception(sprintf('Failed to uncompress %s: %s', $this->fileSource->File, $strError));
             }
             break;
         case 'dtd':
         case 'properties':
         case 'ini':
         case 'inc':
         case 'po':
         case 'sdf':
         case 'svg':
         case 'dpo':
         case 'srt':
         case 'php':
             copy($this->fileSource->File, $this->strWorkingDirectory . '/' . $this->fileSource->FileName);
             chmod($this->strWorkingDirectory . '/' . $this->fileSource->FileName, 0666);
             NarroLogger::LogInfo(sprintf('Single file uploaded, copied %s to %s', $this->fileSource->FileName, $this->strWorkingDirectory));
             break;
         default:
             throw new Exception(sprintf('Unsupported file type uploaded'));
     }
     if (file_exists($this->fileSource->File)) {
         unlink($this->fileSource->File);
     }
     $this->fileSource->btnDelete_Click();
     $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode);
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode . '-' . $this->objLanguage->CountryCode);
     }
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($this->strWorkingDirectory, $this->objLanguage->LanguageCode . '_' . $this->objLanguage->CountryCode);
     }
     NarroUtils::RecursiveChmod($this->strWorkingDirectory);
     if (is_array($arrSearchResult) && count($arrSearchResult) == 1) {
         NarroLogger::LogWarn(sprintf('Path changed from "%s" to "%s" because a directory named "%s" was found deeper in the given path.', $this->strWorkingDirectory, $arrSearchResult[0], $this->objLanguage->LanguageCode));
         $this->strWorkingDirectory = $arrSearchResult[0];
     }
     if ($this->chkCopyFilesToDefaultDirectory->Checked) {
         if (file_exists(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode)) {
             NarroUtils::RecursiveDelete(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode . '/*');
         } else {
             mkdir(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode, 0777);
         }
         NarroUtils::RecursiveCopy($this->strWorkingDirectory, __IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode);
         NarroUtils::RecursiveChmod(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode);
     }
     return $this->strWorkingDirectory;
 }
예제 #3
0
 public function ExportToXpi($strXpiFilePath)
 {
     $strArchive = $this->strTranslationPath . '/' . basename($strXpiFilePath);
     if (file_exists($strArchive)) {
         unlink($strArchive);
     }
     $strWorkingDir = $strXpiFilePath . '_extract';
     mkdir($strWorkingDir, 0777);
     NarroLogger::LogInfo(sprintf('Trying to uncompress %s', $strXpiFilePath));
     $objZipFile = new ZipArchive();
     $intErrCode = $objZipFile->open($strXpiFilePath);
     if ($intErrCode === TRUE) {
         $objZipFile->extractTo($strWorkingDir);
         $objZipFile->close();
         NarroLogger::LogInfo(sprintf('Sucessfully uncompressed %s.', $strXpiFilePath));
     } else {
         switch ($intErrCode) {
             case ZIPARCHIVE::ER_NOZIP:
                 $strError = 'Not a zip archive';
                 break;
             default:
                 $strError = 'Error code: ' . $intErrCode;
         }
         throw new Exception(sprintf('Failed to uncompress %s: %s', $strXpiFilePath, $strError));
     }
     NarroUtils::RecursiveChmod($strWorkingDir);
     // Search source directory
     $arrSearchResult = NarroUtils::SearchDirectoryByName($strWorkingDir, $this->objSourceLanguage->LanguageCode);
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($strWorkingDir, $this->objSourceLanguage->LanguageCode . '-' . $this->objSourceLanguage->CountryCode);
     }
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($strWorkingDir, $this->objSourceLanguage->LanguageCode . '_' . $this->objSourceLanguage->CountryCode);
     }
     if (is_array($arrSearchResult) && count($arrSearchResult) == 1) {
         NarroLogger::LogWarn(sprintf('Path changed from "%s" to "%s" because a directory named "%s" was found deeper in the given path.', $strWorkingDir, $arrSearchResult[0], $this->objSourceLanguage->LanguageCode));
         $strTemplatePath = $arrSearchResult[0];
     }
     // Search target directory
     $arrSearchResult = NarroUtils::SearchDirectoryByName($strWorkingDir, $this->objTargetLanguage->LanguageCode);
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($strWorkingDir, $this->objTargetLanguage->LanguageCode . '-' . $this->objTargetLanguage->CountryCode);
     }
     if ($arrSearchResult == false) {
         $arrSearchResult = NarroUtils::SearchDirectoryByName($strWorkingDir, $this->objTargetLanguage->LanguageCode . '_' . $this->objTargetLanguage->CountryCode);
     }
     if (is_array($arrSearchResult) && count($arrSearchResult) == 1) {
         NarroLogger::LogWarn(sprintf('Path changed from "%s" to "%s" because a directory named "%s" was found deeper in the given path.', $strWorkingDir, $arrSearchResult[0], $this->objTargetLanguage->LanguageCode));
         $strTranslationPath = $arrSearchResult[0];
     }
     if (isset($strTemplatePath)) {
         $strOldTemplatePath = $this->strTemplatePath;
         $this->strTemplatePath = $strTemplatePath;
         if (isset($strTranslationPath)) {
             $this->strTranslationPath = $strTranslationPath;
         }
         $this->ExportFromDirectory();
         $arrFiles = NarroUtils::ListDirectory($strWorkingDir, null, null, null, true);
         $objZipFile = new ZipArchive();
         if ($objZipFile->open($strArchive, ZipArchive::OVERWRITE) === TRUE) {
             foreach ($arrFiles as $strFileName) {
                 if (basename($strFileName) == 'chrome.manifest') {
                     $strManifest = file_get_contents($strFileName);
                     preg_match_all('/^locale\\s+([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)\\s+/m', $strManifest, $arrMatches);
                     if (isset($arrMatches[2]) && in_array($this->objTargetLanguage->LanguageCode, $arrMatches[2])) {
                         // locale already in the manifest
                         NarroLogger::LogInfo('Locale already in the manifest');
                     } else {
                         $strLastLocaleCode = $arrMatches[2][count($arrMatches[2]) - 1];
                         $strLastLocaleLine = $arrMatches[0][count($arrMatches[2]) - 1];
                         $strLastLocalePath = $arrMatches[3][count($arrMatches[2]) - 1];
                         $strManifest = str_replace($strLastLocaleLine, $strLastLocaleLine . "\n" . sprintf('locale %s %s %s', $arrMatches[1][count($arrMatches[2]) - 1], $this->objTargetLanguage->LanguageCode, preg_replace('/\\/[^\\/]+\\/\\s*$/m', '/' . $this->objTargetLanguage->LanguageCode . '/', $strLastLocalePath)), $strManifest);
                     }
                 }
                 if ($strWorkingDir == $strFileName) {
                     continue;
                 }
                 if (is_dir($strFileName)) {
                     $objZipFile->addEmptyDir(str_replace($strWorkingDir . '/', '', $strFileName));
                 } elseif (is_file($strFileName)) {
                     $objZipFile->addFile($strFileName, str_replace($strWorkingDir . '/', '', $strFileName));
                 }
             }
             $objZipFile->close();
             if (file_exists($strArchive)) {
                 chmod($strArchive, 0666);
             } else {
                 NarroLogger::LogError(sprintf('Failed to create an archive %s', $strArchive));
                 NarroUtils::RecursiveDelete($strWorkingDir);
                 return false;
             }
         } else {
             NarroLogger::LogError(sprintf('Failed to create a new archive %s', $strArchive));
             NarroUtils::RecursiveDelete($strWorkingDir);
             return false;
         }
     }
     NarroUtils::RecursiveDelete($strWorkingDir);
     return true;
 }