public function ChangeDirectory($strPath) { if ($strPath) { $this->objParentFile = NarroFile::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroFile()->ProjectId, $this->objProject->ProjectId), QQ::Equal(QQN::NarroFile()->Active, 1), QQ::Equal(QQN::NarroFile()->FilePath, $strPath))); } $this->pnlBreadcrumb->Visible = false; $this->pnlBreadcrumb->setElements(NarroLink::ProjectFileList($this->objProject->ProjectId, null, null, '..')); if ($this->objParentFile) { $arrPaths = explode('/', $this->objParentFile->FilePath); $strProgressivePath = ''; if (is_array($arrPaths)) { /** * remove the first part that is empty because paths begin with / * and the last part that will be displayed unlinked */ unset($arrPaths[count($arrPaths) - 1]); unset($arrPaths[0]); foreach ($arrPaths as $intCnt => $strPathPart) { $strProgressivePath .= '/' . $strPathPart; $this->pnlBreadcrumb->addElement(NarroLink::ProjectFileList($this->objProject->ProjectId, $strProgressivePath, null, $strPathPart)); } } } if ($this->objParentFile instanceof NarroFile) { $this->pnlBreadcrumb->addElement($this->objParentFile->FileName); $this->pnlBreadcrumb->Visible = true; } }
/** * Load a single NarroFile object, * by FileName, ParentId Index(es) * @param string $strFileName * @param integer $intParentId * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query * @return NarroFile */ public static function LoadByFileNameParentId($strFileName, $intParentId, $objOptionalClauses = null) { return NarroFile::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroFile()->FileName, $strFileName), QQ::Equal(QQN::NarroFile()->ParentId, $intParentId)), $objOptionalClauses); }
public function ExportFromDirectory() { // NarroLogger::LogDebug(sprintf('Starting to export in directory "%s"', $this->strTranslationPath)); /** * get the file list with complete paths */ $arrFiles = $this->ListDir($this->strTemplatePath); $intTotalFilesToProcess = count($arrFiles); if ($intTotalFilesToProcess == 1 && pathinfo($arrFiles[0], PATHINFO_EXTENSION) == 'xpi') { return $this->ExportToXpi($arrFiles[0]); } if ($intTotalFilesToProcess > __MAXIMUM_FILE_COUNT_TO_EXPORT__) { NarroLogger::LogError(sprintf('Too many files to process: %d. The maximum number of files to export is set in the configuration file at %d', $intTotalFilesToProcess, __MAXIMUM_FILE_COUNT_TO_EXPORT__)); return false; } // NarroLogger::LogDebug(sprintf('Starting to process %d files', $intTotalFilesToProcess)); $arrDirectories = array(); NarroProgress::SetProgress(0, $this->objProject->ProjectId, 'export', $intTotalFilesToProcess); if (is_array($arrFiles)) { foreach ($arrFiles as $intFileNo => $strFileToExport) { $arrFileParts = explode('/', str_replace($this->strTemplatePath, '', $strFileToExport)); $strFileName = $arrFileParts[count($arrFileParts) - 1]; unset($arrFileParts[count($arrFileParts) - 1]); unset($arrFileParts[0]); $strPath = ''; $intParentId = null; $arrDirectories = array(); foreach ($arrFileParts as $intPos => $strDir) { $strPath = $strPath . '/' . $strDir; if (!isset($arrDirectories[$strPath])) { if (!is_null($intParentId)) { $objFile = NarroFile::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroFile()->ProjectId, $this->objProject->ProjectId), QQ::Equal(QQN::NarroFile()->FileName, $strDir), QQ::Equal(QQN::NarroFile()->TypeId, NarroFileType::Folder), QQ::Equal(QQN::NarroFile()->ParentId, $intParentId))); } else { $objFile = NarroFile::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroFile()->ProjectId, $this->objProject->ProjectId), QQ::Equal(QQN::NarroFile()->FileName, $strDir), QQ::Equal(QQN::NarroFile()->TypeId, NarroFileType::Folder), QQ::IsNull(QQN::NarroFile()->ParentId))); } if (!$objFile instanceof NarroFile) { NarroLogger::LogWarn(sprintf('Could not find folder "%s" with parent id "%d" in the database.', $strDir, $intParentId)); continue; } $arrDirectories[$strPath] = $objFile->FileId; } $intParentId = $arrDirectories[$strPath]; } $strTranslatedFileToExport = str_replace($this->strTemplatePath, $this->strTranslationPath, $strFileToExport); if (!file_exists(dirname($strTranslatedFileToExport))) { if (!mkdir(dirname($strTranslatedFileToExport), 0777, true)) { NarroLogger::LogWarn(sprintf('Failed to create the parent directories for the file %s', $strFileToExport)); return false; } NarroUtils::RecursiveChmod(dirname($strTranslatedFileToExport)); } $objFile = NarroFile::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroFile()->ProjectId, $this->objProject->ProjectId), QQ::Equal(QQN::NarroFile()->FileName, $strFileName), QQ::Equal(QQN::NarroFile()->ParentId, $intParentId), QQ::Equal(QQN::NarroFile()->Active, 1))); if (!$objFile instanceof NarroFile) { continue; } // NarroLogger::LogDebug(sprintf('Exporting file "%s" using template "%s"', $objFile->FileName, $strTranslatedFileToExport)); $intTime = time(); $this->ExportFile($objFile, $strFileToExport, $strTranslatedFileToExport); $intElapsedTime = time() - $intTime; // NarroLogger::LogDebug(sprintf('Processed file "%s" in %d seconds, %d files left', str_replace($this->strTemplatePath, '', $strFileToExport), $intElapsedTime, (count($arrFiles) - $intFileNo - 1))); NarroImportStatistics::$arrStatistics['Exported files']++; NarroProgress::SetProgress((int) ceil($intFileNo * 100 / $intTotalFilesToProcess), $this->objProject->ProjectId, 'export'); } } return true; }