public function __get($strName)
 {
     switch ($strName) {
         case "Directory":
             if ($this->chkCopyFilesToDefaultDirectory->Checked && __IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode != $this->txtDirectory->Text) {
                 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->txtDirectory->Text, __IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode);
                 NarroUtils::RecursiveChmod(__IMPORT_PATH__ . '/' . $this->objProject->ProjectId . '/' . $this->objLanguage->LanguageCode);
             }
             return $this->txtDirectory->Text;
         default:
             try {
                 return parent::__get($strName);
                 break;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
     }
 }
 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;
 }
 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;
 }
示例#4
0
 public function SaveData($mixData)
 {
     $mixResult = parent::SaveData(serialize($mixData));
     NarroUtils::RecursiveChmod(__CACHE__);
     return $mixResult;
 }
示例#5
0
 public function Save($blnForceInsert = false, $blnForceUpdate = false)
 {
     $blnNew = !$this->__blnRestored || $blnForceInsert;
     $objProjectProgress = NarroProjectProgress::LoadByProjectIdLanguageId($this->intProjectId, QApplication::GetLanguageId());
     if (is_array($this->arrPreferences)) {
         foreach ($this->arrPreferences as $strName => $strValue) {
             if (self::$AvailablePreferences[$strName]['global'] == false) {
                 if ($objProjectProgress) {
                     $objProjectProgress->SetPreferenceValueByName($strName, $strValue);
                 }
             } else {
                 $arrGlobalPreferences[$strName] = $strValue;
             }
         }
     }
     if (isset($arrGlobalPreferences)) {
         $this->strData = serialize($arrGlobalPreferences);
     }
     if ($objProjectProgress) {
         $objProjectProgress->Save();
     }
     $mixResult = parent::Save($blnForceInsert, $blnForceUpdate);
     if ($blnNew) {
         if (!file_exists(__IMPORT_PATH__ . '/' . $this->ProjectId)) {
             @mkdir(__IMPORT_PATH__ . '/' . $this->ProjectId, 0777, true);
             NarroUtils::RecursiveChmod(__IMPORT_PATH__ . '/' . $this->ProjectId);
         }
         if (!file_exists($this->DefaultTemplatePath)) {
             @mkdir($this->DefaultTemplatePath, 0777, true);
             NarroUtils::RecursiveChmod($this->DefaultTemplatePath);
         }
         foreach (NarroLanguage::LoadAll() as $objLanguage) {
             $objProjectProgress = new NarroProjectProgress();
             $objProjectProgress->LanguageId = $objLanguage->LanguageId;
             $objProjectProgress->ProjectId = $this->ProjectId;
             $objProjectProgress->Active = $this->Active;
             $objProjectProgress->TotalTextCount = 0;
             $objProjectProgress->ApprovedTextCount = 0;
             $objProjectProgress->FuzzyTextCount = 0;
             $objProjectProgress->ProgressPercent = 0;
             $objProjectProgress->Active = $this->Active;
             $objProjectProgress->LastModified = QDateTime::Now();
             $objProjectProgress->Save();
             if (!file_exists($this->DefaultTranslationPath)) {
                 @mkdir($this->DefaultTranslationPath, 0777, true);
             }
             NarroUtils::RecursiveChmod($this->DefaultTranslationPath, 0666, 0777);
         }
     }
     return $mixResult;
 }
 public function __set($strName, $mixValue)
 {
     switch ($strName) {
         case "TranslationPath":
             if (file_exists($mixValue)) {
                 $this->strTranslationPath = $mixValue;
             } else {
                 if (!file_exists(dirname($mixValue))) {
                     throw new Exception(sprintf('Cannot create "%s" because the parent directory "%s" does not exist', $mixValue, dirname($mixValue)));
                 }
                 if (!is_writable(dirname($mixValue))) {
                     throw new Exception(sprintf('Cannot create "%s" because the parent directory "%s" is not writable', $mixValue, dirname($mixValue)));
                 }
                 chmod(dirname($mixValue), 0777);
                 if (mkdir($mixValue, 0777, true)) {
                     $this->strTranslationPath = $mixValue;
                 } else {
                     throw new Exception(sprintf(t('TranslationPath "%s" does not exist.'), $mixValue));
                 }
                 NarroUtils::RecursiveChmod($mixValue);
             }
             break;
         case "TemplatePath":
             if (file_exists($mixValue)) {
                 $this->strTemplatePath = $mixValue;
             } else {
                 if (!file_exists(dirname($mixValue))) {
                     throw new Exception(sprintf('Cannot create "%s" because the parent directory "%s" does not exist', $mixValue, dirname($mixValue)));
                 }
                 if (!is_writable(dirname($mixValue))) {
                     throw new Exception(sprintf('Cannot create "%s" because the parent directory "%s" is not writable', $mixValue, dirname($mixValue)));
                 }
                 chmod(dirname($mixValue), 0777);
                 if (mkdir($mixValue, 0777, true)) {
                     $this->strTranslationPath = $mixValue;
                 } else {
                     throw new Exception(sprintf(t('TranslationPath "%s" does not exist.'), $mixValue));
                 }
                 NarroUtils::RecursiveChmod($mixValue);
             }
             break;
         case "User":
             if ($mixValue instanceof NarroUser) {
                 $this->objUser = $mixValue;
             } else {
                 throw new Exception(t('User should be set with an instance of NarroUser'));
             }
             break;
         case "Project":
             if ($mixValue instanceof NarroProject) {
                 $this->objProject = $mixValue;
             } else {
                 throw new Exception(t('Project should be set with an instance of NarroProject'));
             }
             break;
         case "TargetLanguage":
             if ($mixValue instanceof NarroLanguage) {
                 $this->objTargetLanguage = $mixValue;
             } else {
                 throw new Exception(t('TargetLanguage should be set with an instance of NarroLanguage'));
             }
             break;
         case "SourceLanguage":
             if ($mixValue instanceof NarroLanguage) {
                 $this->objSourceLanguage = $mixValue;
             } else {
                 throw new Exception(t('SourceLanguage should be set with an instance of NarroLanguage'));
             }
             break;
         case "Approve":
             try {
                 $this->blnApprove = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "SkipUntranslated":
             try {
                 $this->blnSkipUntranslated = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "ApproveAlreadyApproved":
             try {
                 $this->blnApproveAlreadyApproved = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "CheckEqual":
             try {
                 $this->blnCheckEqual = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "ImportUnchangedFiles":
             try {
                 $this->blnImportUnchangedFiles = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "ImportSuggestions":
             try {
                 $this->blnImportSuggestions = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "CopyUnhandledFiles":
             try {
                 $this->blnCopyUnhandledFiles = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "OnlySuggestions":
             try {
                 $this->blnOnlySuggestions = QType::Cast($mixValue, QType::Boolean);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "ExportedSuggestion":
             try {
                 $this->intExportedSuggestion = QType::Cast($mixValue, QType::Integer);
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case "ExportAuthorList":
             try {
                 if (is_array($mixValue)) {
                     $this->arrExportAuthorList = QType::Cast($mixValue, QType::ArrayType);
                 } else {
                     $arrAuthor = explode(',', $mixValue);
                     foreach ($arrAuthor as $intIdx => $strAuthor) {
                         $arrAuthor[$intIdx] = trim($strAuthor);
                     }
                     foreach (NarroUser::QueryArray(QQ::In(QQN::NarroUser()->RealName, $arrAuthor)) as $objUser) {
                         $this->arrExportAuthorList[] = $objUser->UserId;
                     }
                 }
                 break;
             } catch (QInvalidCastException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         default:
             return false;
     }
 }
 public static function SplitFile($strFile, $strPath, $arrLocale = array(NarroLanguage::SOURCE_LANGUAGE_CODE))
 {
     $hndFile = fopen($strFile, 'r');
     if (!$hndFile) {
         NarroLogger::LogError(sprintf('Cannot open input file "%s" for reading.', $strFile));
         return false;
     }
     /**
      * read the template file line by line
      */
     while (!feof($hndFile)) {
         $strFileLine = fgets($hndFile);
         /**
          * OpenOffice uses tab separated values
          */
         $arrColumn = preg_split('/\\t/', $strFileLine);
         if (count($arrColumn) < 14) {
             continue;
         }
         if (!in_array($arrColumn[9], $arrLocale)) {
             continue;
         }
         $strFilePath = $strPath . '/' . $arrColumn[0] . '/' . str_replace('\\', '/', $arrColumn[1]) . '.sdf';
         if (!file_exists($strFilePath)) {
             if (!file_exists(dirname($strFilePath))) {
                 mkdir(dirname($strFilePath), 0777, true);
             }
         }
         $hndSplitFile = fopen($strFilePath, 'a+');
         fputs($hndSplitFile, $strFileLine);
         fclose($hndSplitFile);
     }
     NarroUtils::RecursiveChmod($strPath);
 }