本文整理汇总了PHP中FileManager::copyFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FileManager::copyFile方法的具体用法?PHP FileManager::copyFile怎么用?PHP FileManager::copyFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::copyFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: migrateSubmissionFilePaths
/**
* For 3.0.0 upgrade. Migrates submission files to new paths.
*/
function migrateSubmissionFilePaths()
{
$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
import('lib.pkp.classes.submission.SubmissionFile');
$genreDao = DAORegistry::getDAO('GenreDAO');
$journalDao = DAORegistry::getDAO('JournalDAO');
$submissionFile = new SubmissionFile();
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$articleFilesResult = $submissionFileDao->retrieve('SELECT af.*, s.submission_id, s.context_id FROM article_files_migration af, submissions s WHERE af.article_id = s.submission_id');
$filesDir = Config::getVar('files', 'files_dir') . '/journals/';
while (!$articleFilesResult->EOF) {
$row = $articleFilesResult->GetRowAssoc(false);
// Assemble the old file path.
$oldFilePath = $filesDir . $row['context_id'] . '/articles/' . $row['submission_id'] . '/';
if (isset($row['type'])) {
// pre 2.4 upgrade.
$oldFilePath .= $row['type'];
} else {
// post 2.4, we have file_stage instead.
switch ($row['file_stage']) {
case 1:
$oldFilePath .= 'submission/original';
break;
case 2:
$oldFilePath .= 'submission/review';
break;
case 3:
$oldFilePath .= 'submission/editor';
break;
case 4:
$oldFilePath .= 'submission/copyedit';
break;
case 5:
$oldFilePath .= 'submission/layout';
break;
case 6:
$oldFilePath .= 'supp';
break;
case 7:
$oldFilePath .= 'public';
break;
case 8:
$oldFilePath .= 'note';
break;
case 9:
$oldFilePath .= 'attachment';
break;
}
}
$oldFilePath .= '/' . $row['file_name'];
if (file_exists($oldFilePath)) {
// sanity check.
$newFilePath = $filesDir . $row['context_id'] . '/articles/' . $row['submission_id'] . '/';
// Since we cannot be sure that we had a file_stage column before, query the new submission_files table.
$submissionFileResult = $submissionFileDao->retrieve('SELECT genre_id, file_stage, date_uploaded, original_file_name
FROM submission_files WHERE file_id = ? and revision = ?', array($row['file_id'], $row['revision']));
$submissionFileRow = $submissionFileResult->GetRowAssoc(false);
$newFilePath .= $submissionFile->_fileStageToPath($submissionFileRow['file_stage']);
$genre = $genreDao->getById($submissionFileRow['genre_id']);
// pull in the primary locale for this journal without loading the whole object.
$localeResult = $journalDao->retrieve('SELECT primary_locale FROM journals WHERE journal_id = ?', array($row['context_id']));
$localeRow = $localeResult->GetRowAssoc(false);
$newFilePath .= '/' . $row['submission_id'] . '-' . $genre->getDesignation() . '_' . $genre->getName($localeRow['primary_locale']) . '-' . $row['file_id'] . '-' . $row['revision'] . '-' . $submissionFileRow['file_stage'] . '-' . date('Ymd', strtotime($submissionFileRow['date_uploaded'])) . '.' . strtolower_codesafe($fileManager->parseFileExtension($submissionFileRow['original_file_name']));
$fileManager->copyFile($oldFilePath, $newFilePath);
if (file_exists($newFilePath)) {
$fileManager->deleteFile($oldFilePath);
}
}
$articleFilesResult->MoveNext();
unset($localeResult);
unset($submissionFileResult);
unset($localeRow);
unset($submissionFileRow);
}
return true;
}
示例2: exportObjects
/**
* Export publishing objects.
*
* @param $request Request
* @param $exportSpec array An array with DOI_EXPORT_* constants as keys and
* object ids as values.
* @param $journal Journal
* @param $outputFile string The final file to export to (if not given then a
* standard file name convention will be used).
*
* @return boolean|array True for success or an array of error messages.
*/
function exportObjects($request, $exportSpec, $journal, $outputFile = null)
{
// Initialize local variables.
$errors = array();
// If we have more than one object type, then we'll need the
// tar tool to package the resulting export files. Check this
// early on to avoid unnecessary export processing.
if (count($exportSpec) > 1) {
if (is_array($errors = $this->_checkForTar())) {
return $errors;
}
}
// Get the target directory.
$result = $this->_getExportPath();
if (is_array($result)) {
return $result;
}
$exportPath = $result;
// Run through the export spec and generate the corresponding
// export files.
$exportFiles = $this->_generateExportFilesForObjects($request, $journal, $exportSpec, $exportPath, $errors);
if ($exportFiles === false) {
return $errors;
}
// Check whether we need the tar tool for this export if
// we've not checked this before.
if (count($exportFiles) > 1 && !$this->_checkedForTar) {
if (is_array($errors = $this->_checkForTar())) {
$this->cleanTmpfiles($exportPath, array_keys($exportFiles));
return $errors;
}
}
// If we have more than one export file we package the files
// up as a single tar before going on.
assert(count($exportFiles) >= 1);
if (count($exportFiles) > 1) {
$finalExportFileName = $exportPath . $this->getPluginId() . '-export.tar.gz';
$finalExportFileType = DOI_EXPORT_FILE_TAR;
$this->tarFiles($exportPath, $finalExportFileName, array_keys($exportFiles));
$exportFiles[$finalExportFileName] = array();
} else {
$finalExportFileName = key($exportFiles);
$finalExportFileType = DOI_EXPORT_FILE_XML;
}
// Stream the results to the browser...
if (is_null($outputFile)) {
header('Content-Type: application/' . ($finalExportFileType == DOI_EXPORT_FILE_TAR ? 'x-gtar' : 'xml'));
header('Cache-Control: private');
header('Content-Disposition: attachment; filename="' . basename($finalExportFileName) . '"');
readfile($finalExportFileName);
// ...or save them as a file.
} else {
$outputFileExtension = $finalExportFileType == DOI_EXPORT_FILE_TAR ? '.tar.gz' : '.xml';
if (substr($outputFile, -strlen($outputFileExtension)) != $outputFileExtension) {
$outputFile .= $outputFileExtension;
}
$outputDir = dirname($outputFile);
if (empty($outputDir)) {
$outputDir = getcwd();
}
if (!is_writable($outputDir) || file_exists($outputFile) && !is_writable($outputFile)) {
$this->cleanTmpfiles($exportPath, array_keys($exportFiles));
$errors[] = array('plugins.importexport.common.export.error.outputFileNotWritable', $outputFile);
return $errors;
}
$fileManager = new FileManager();
$fileManager->copyFile($finalExportFileName, $outputFile);
}
// Remove all temporary files.
$this->cleanTmpfiles($exportPath, array_keys($exportFiles));
return true;
}
示例3: createFile
function createFile($args, $request)
{
$this->validate();
$plugin =& $this->plugin;
$this->setupTemplate($request);
$locale = array_shift($args);
if (!AppLocale::isLocaleValid($locale)) {
$request->redirect(null, null, 'index');
}
$filename = urldecode(urldecode(array_shift($args)));
if (!TranslatorAction::isLocaleFile($locale, $filename)) {
$request->redirect(null, null, 'edit', $locale);
}
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$fileManager->copyFile(TranslatorAction::determineReferenceFilename($locale, $filename), $filename);
$request->redirectUrl($request->getUserVar('redirectUrl'));
}
示例4: copyDir
/**
* Copy a directory.
* Adapted from code by gimmicklessgpt at gmail dot com, at http://php.net/manual/en/function.copy.php
* @param $source string the path to the source directory
* @param $dest string the path where the directory is to be saved
* @return boolean returns true if successful
*/
function copyDir($source, $dest)
{
if (is_dir($source)) {
FileManager::mkdir($dest);
$destDir = dir($source);
while (($entry = $destDir->read()) !== false) {
if ($entry == '.' || $entry == '..') {
continue;
}
$Entry = $source . DIRECTORY_SEPARATOR . $entry;
if (is_dir($Entry)) {
FileManager::copyDir($Entry, $dest . DIRECTORY_SEPARATOR . $entry);
continue;
}
FileManager::copyFile($Entry, $dest . DIRECTORY_SEPARATOR . $entry);
}
$destDir->close();
} else {
FileManager::copyFile($source, $target);
}
if (FileManager::fileExists($dest, 'dir')) {
return true;
} else {
return false;
}
}
示例5: installPlugin
/**
* Install or upgrade a plugin
*/
function installPlugin($args, $request, $isUpgrade = false)
{
$plugin = $this->_getSpecifiedPlugin($request);
$notificationMgr = new NotificationManager();
$user = $request->getUser();
$dispatcher = $request->getDispatcher();
// Download the file and ensure the MD5 sum
$fileManager = new FileManager();
$destPath = tempnam(sys_get_temp_dir(), 'plugin');
$fileManager->copyFile($plugin->getReleasePackage(), $destPath);
if (md5_file($destPath) !== $plugin->getReleaseMD5()) {
fatalError('Incorrect MD5 checksum!');
}
// Extract the plugin
import('lib.pkp.classes.plugins.PluginHelper');
$pluginHelper = new PluginHelper();
$errorMsg = null;
if (!($pluginDir = $pluginHelper->extractPlugin($destPath, $plugin->getProduct() . '-' . $plugin->getVersion(), $errorMsg))) {
$notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => $errorMsg));
}
// Install the plugin
if (!$isUpgrade) {
if (!($pluginVersion = $pluginHelper->installPlugin($pluginDir, $errorMsg))) {
$notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => $errorMsg));
}
} else {
if (!($pluginVersion = $pluginHelper->upgradePlugin($plugin->getCategory(), $plugin->getProduct(), $pluginDir, $errorMsg))) {
$notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => $errorMsg));
}
}
if (!$errorMsg) {
$notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('manager.plugins.upgradeSuccessful', array('versionString' => $pluginVersion->getVersionString(false)))));
}
return $request->redirectUrlJson($dispatcher->url($request, ROUTE_PAGE, null, 'management', 'settings', array('website'), null, 'plugins'));
}
示例6: handleExport
function handleExport(&$journal, &$errors, $outputFile = null)
{
$this->import('XMLAssembler');
import('classes.file.PublicFileManager');
import('classes.file.JournalFileManager');
$isTarOk = $this->_checkForTar();
if (is_array($isTarOk)) {
$errors = $isTarOk;
return false;
}
$tmpPath = $this->_getTmpPath();
if (is_array($tmpPath)) {
$errors = $tmpPath;
return false;
}
$xmlAbsolutePath = $this->_generateXml($journal, $tmpPath);
if ($xmlAbsolutePath === false) {
return false;
}
$publicFileManager = new PublicFileManager();
$journalFileManager = new JournalFileManager($journal);
$journalPublicPath = $publicFileManager->getJournalFilesPath($journal->getId());
$sitePublicPath = $publicFileManager->getSiteFilesPath();
$journalFilesPath = $journalFileManager->filesDir;
$exportFiles = array();
$exportFiles[$xmlAbsolutePath] = "journal.xml";
$exportFiles[$journalPublicPath] = "public";
$exportFiles[$journalFilesPath] = "files";
$exportFiles[$sitePublicPath] = "sitePublic";
// Package the files up as a single tar before going on.
$finalExportFileName = $tmpPath . $journal->getPath() . ".tar.gz";
$this->tarFiles($tmpPath, $finalExportFileName, $exportFiles);
if (is_null($outputFile)) {
header('Content-Type: application/x-gtar');
header('Cache-Control: private');
header('Content-Disposition: attachment; filename="' . $journal->getPath() . '.tar.gz"');
readfile($finalExportFileName);
} else {
$outputFileExtension = '.tar.gz';
if (substr($outputFile, -strlen($outputFileExtension)) != $outputFileExtension) {
$outputFile .= $outputFileExtension;
}
$outputDir = dirname($outputFile);
if (empty($outputDir)) {
$outputDir = getcwd();
}
if (!is_writable($outputDir)) {
$this->_removeTemporaryFiles(array_keys($xmlAbsolutePath));
$errors[] = array('plugins.importexport.common.export.error.outputFileNotWritable', $outputFile);
return $errors;
}
$fileManager = new FileManager();
$fileManager->copyFile($finalExportFileName, $outputFile);
}
$this->_removeTemporaryFiles(array($xmlAbsolutePath, $finalExportFileName));
return true;
}
示例7: pathinfo
/**
* Copy the passed file, filtering entries
* related to this installation.
* @param $filePath string
*/
function _copyFile($filePath)
{
$usageStatsFiles = $this->_usageStatsFiles;
$usageStatsDir = $this->_usageStatsDir;
$tmpDir = $this->_tmpDir;
$fileName = pathinfo($filePath, PATHINFO_BASENAME);
$fileMgr = new FileManager();
$isCompressed = false;
$uncompressedFileName = $fileName;
if (pathinfo($filePath, PATHINFO_EXTENSION) == 'gz') {
$isCompressed = true;
$uncompressedFileName = substr($fileName, 0, -3);
}
if (in_array($uncompressedFileName, $usageStatsFiles)) {
printf(__('admin.copyAccessLogFileTool.warning.fileAlreadyExists', array('filePath' => $filePath)) . "\n");
return;
}
$tmpFilePath = $tmpDir . DIRECTORY_SEPARATOR . $fileName;
// Copy the file to a temporary directory.
if (!$fileMgr->copyFile($filePath, $tmpFilePath)) {
printf(__('admin.copyAccessLogFileTool.error.copyingFile', array('filePath' => $filePath, 'tmpFilePath' => $tmpFilePath)) . "\n");
exit(1);
}
// Uncompress it, if needed.
if ($isCompressed) {
$fileMgr = new FileManager();
$errorMsg = null;
if (!($tmpFilePath = $fileMgr->decompressFile($tmpFilePath, $errorMsg))) {
printf($errorMsg . "\n");
exit(1);
}
}
// Filter only entries that contains context paths.
$egrepPath = $this->_egrepPath;
$destinationPath = $usageStatsDir . DIRECTORY_SEPARATOR . FILE_LOADER_PATH_STAGING . DIRECTORY_SEPARATOR . pathinfo($tmpFilePath, PATHINFO_BASENAME);
// Each context path is already escaped, see the constructor.
$output = null;
$returnValue = 0;
exec($egrepPath . " -i '" . $this->_contextPaths . "' " . escapeshellarg($tmpFilePath) . " > " . escapeshellarg($destinationPath), $output, $returnValue);
if ($returnValue > 1) {
printf(__('admin.error.executingUtil', array('utilPath' => $egrepPath, 'utilVar' => 'egrep')) . "\n");
exit(1);
}
if (!$fileMgr->deleteFile($tmpFilePath)) {
printf(__('admin.copyAccessLogFileTool.error.deletingFile', array('tmpFilePath' => $tmpFilePath)) . "\n");
exit(1);
}
printf(__('admin.copyAccessLogFileTool.success', array('filePath' => $filePath, 'destinationPath' => $destinationPath)) . "\n");
}
示例8: updateObject
/**
* Update a submission file.
* @param $submissionFile SubmissionFile The target state
* of the updated file.
* @param $previousFile SubmissionFile The current state
* of the updated file.
* @return boolean
*/
function updateObject($submissionFile, $previousFile)
{
// Update the file in the database.
$this->update(sprintf('UPDATE submission_files
SET
file_id = ?,
revision = ?,
submission_id = ?,
source_file_id = ?,
source_revision = ?,
file_type = ?,
file_size = ?,
original_file_name = ?,
file_stage = ?,
date_uploaded = %s,
date_modified = %s,
viewable = ?,
uploader_user_id = ?,
user_group_id = ?,
assoc_type = ?,
assoc_id = ?,
genre_id = ?,
direct_sales_price = ?,
sales_type = ?
WHERE file_id = ? AND revision = ?', $this->datetimeToDB($submissionFile->getDateUploaded()), $this->datetimeToDB($submissionFile->getDateModified())), array((int) $submissionFile->getFileId(), (int) $submissionFile->getRevision(), (int) $submissionFile->getSubmissionId(), is_null($submissionFile->getSourceFileId()) ? null : (int) $submissionFile->getSourceFileId(), is_null($submissionFile->getSourceRevision()) ? null : (int) $submissionFile->getSourceRevision(), $submissionFile->getFileType(), $submissionFile->getFileSize(), $submissionFile->getOriginalFileName(), $submissionFile->getFileStage(), (bool) $submissionFile->getViewable() ? 1 : 0, is_null($submissionFile->getUploaderUserId()) ? null : (int) $submissionFile->getUploaderUserId(), is_null($submissionFile->getUserGroupId()) ? null : (int) $submissionFile->getUserGroupId(), is_null($submissionFile->getAssocType()) ? null : (int) $submissionFile->getAssocType(), is_null($submissionFile->getAssocId()) ? null : (int) $submissionFile->getAssocId(), is_null($submissionFile->getGenreId()) ? null : (int) $submissionFile->getGenreId(), $submissionFile->getDirectSalesPrice(), $submissionFile->getSalesType(), (int) $previousFile->getFileId(), (int) $previousFile->getRevision()));
$this->updateLocaleFields($submissionFile);
// Update all dependent objects.
$this->_updateDependentObjects($submissionFile, $previousFile);
// Copy the file from its current location to the target destination
// if necessary.
$previousFilePath = $previousFile->getFilePath();
$targetFilePath = $submissionFile->getFilePath();
if ($previousFilePath != $targetFilePath && is_file($previousFilePath)) {
// The file location changed so let's move the file on
// the file system, too.
assert(is_readable($previousFilePath));
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
if (!$fileManager->copyFile($previousFilePath, $targetFilePath)) {
return false;
}
if (!$fileManager->deleteFile($previousFilePath)) {
return false;
}
}
return file_exists($targetFilePath);
}
示例9: UsageStatsLoader
/**
* Constructor.
* @param $argv array task arguments
*/
function UsageStatsLoader($args)
{
$plugin =& PluginRegistry::getPlugin('generic', 'usagestatsplugin');
/* @var $plugin UsageStatsPlugin */
$this->_plugin =& $plugin;
$arg = current($args);
switch ($arg) {
case 'autoStage':
if ($plugin->getSetting(0, 'createLogFiles')) {
$this->_autoStage = true;
}
break;
case 'externalLogFiles':
$this->_externalLogFiles = true;
break;
}
// Define the base filesystem path.
$args[0] = $plugin->getFilesPath();
parent::FileLoader($args);
if ($plugin->getEnabled()) {
// Load the metric type constant.
PluginRegistry::loadCategory('reports');
$geoLocationTool =& StatisticsHelper::getGeoLocationTool();
$this->_geoLocationTool =& $geoLocationTool;
$plugin->import('UsageStatsTemporaryRecordDAO');
$statsDao = new UsageStatsTemporaryRecordDAO();
DAORegistry::registerDAO('UsageStatsTemporaryRecordDAO', $statsDao);
$this->_counterRobotsListFile = $this->_getCounterRobotListFile();
$journalDao =& DAORegistry::getDAO('JournalDAO');
/* @var $journalDao JournalDAO */
$journalFactory =& $journalDao->getJournals();
/* @var $journalFactory DAOResultFactory */
$journalsByPath = array();
while ($journal =& $journalFactory->next()) {
/* @var $journal Journal */
$journalsByPath[$journal->getPath()] =& $journal;
}
$this->_journalsByPath = $journalsByPath;
$this->checkFolderStructure(true);
if ($this->_autoStage) {
// Copy all log files to stage directory, except the current day one.
$fileMgr = new FileManager();
$logFiles = array();
$logsDirFiles = glob($plugin->getUsageEventLogsPath() . DIRECTORY_SEPARATOR . '*');
// It's possible that the processing directory have files that
// were being processed but the php process was stopped before
// finishing the processing. Just copy them to the stage directory too.
$processingDirFiles = glob($this->getProcessingPath() . DIRECTORY_SEPARATOR . '*');
if (is_array($logsDirFiles)) {
$logFiles = array_merge($logFiles, $logsDirFiles);
}
if (is_array($processingDirFiles)) {
$logFiles = array_merge($logFiles, $processingDirFiles);
}
foreach ($logFiles as $filePath) {
// Make sure it's a file.
if ($fileMgr->fileExists($filePath)) {
// Avoid current day file.
$filename = pathinfo($filePath, PATHINFO_BASENAME);
$currentDayFilename = $plugin->getUsageEventCurrentDayLogName();
if ($filename == $currentDayFilename) {
continue;
}
if ($fileMgr->copyFile($filePath, $this->getStagePath() . DIRECTORY_SEPARATOR . $filename)) {
$fileMgr->deleteFile($filePath);
}
}
}
}
}
}
示例10: executeCLICommand
/**
* @copydoc PKPImportExportPlugin::executeCLI()
*/
function executeCLICommand($scriptName, $command, $context, $outputFile, $objects, $filter, $objectsFileNamePart)
{
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
switch ($command) {
case 'export':
$result = $this->_checkForTar();
if ($result === true) {
$exportedFiles = array();
foreach ($objects as $object) {
// Get the XML
$exportXml = $this->exportXML($object, $filter, $context);
// Write the XML to a file.
// export file name example: datacite-20160723-160036-articles-1-1.xml
$objectFileNamePart = $objectsFileNamePart . '-' . $object->getId();
$exportFileName = $this->getExportFileName($this->getExportPath(), $objectFileNamePart, $context, '.xml');
$fileManager->writeFile($exportFileName, $exportXml);
$exportedFiles[] = $exportFileName;
}
// If we have more than one export file we package the files
// up as a single tar before going on.
assert(count($exportedFiles) >= 1);
if (count($exportedFiles) > 1) {
// tar file name: e.g. datacite-20160723-160036-articles-1.tar.gz
$finalExportFileName = $this->getExportFileName($this->getExportPath(), $objectFileNamePart, $context, '.tar.gz');
$finalExportFileType = DATACITE_EXPORT_FILE_TAR;
$this->_tarFiles($this->getExportPath(), $finalExportFileName, $exportedFiles);
} else {
$finalExportFileName = array_shift($exportedFiles);
$finalExportFileType = DATACITE_EXPORT_FILE_XML;
}
$outputFileExtension = $finalExportFileType == DATACITE_EXPORT_FILE_TAR ? '.tar.gz' : '.xml';
if (substr($outputFile, -strlen($outputFileExtension)) != $outputFileExtension) {
$outputFile .= $outputFileExtension;
}
$fileManager->copyFile($finalExportFileName, $outputFile);
foreach ($exportedFiles as $exportedFile) {
$fileManager->deleteFile($exportedFile);
}
$fileManager->deleteFile($finalExportFileName);
} else {
echo __('plugins.importexport.common.cliError') . "\n";
echo __('manager.plugins.tarCommandNotFound') . "\n\n";
$this->usage($scriptName);
}
break;
case 'register':
$resultErrors = array();
foreach ($objects as $object) {
// Get the XML
$exportXml = $this->exportXML($object, $filter, $context);
// Write the XML to a file.
// export file name example: datacite-20160723-160036-articles-1-1.xml
$objectFileNamePart = $objectsFileNamePart . '-' . $object->getId();
$exportFileName = $this->getExportFileName($this->getExportPath(), $objectFileNamePart, $context, '.xml');
$fileManager->writeFile($exportFileName, $exportXml);
// Deposit the XML file.
$result = $this->depositXML($object, $context, $exportFileName);
if (is_array($result)) {
$resultErrors[] = $result;
}
// Remove all temporary files.
$fileManager->deleteFile($exportFileName);
}
if (empty($resultErrors)) {
echo __('plugins.importexport.common.register.success') . "\n";
} else {
echo __('plugins.importexport.common.cliError') . "\n";
foreach ($resultErrors as $errors) {
foreach ($errors as $error) {
assert(is_array($error) && count($error) >= 1);
$errorMessage = __($error[0], array('param' => isset($error[1]) ? $error[1] : null));
echo "*** {$errorMessage}\n";
}
}
echo "\n";
$this->usage($scriptName);
}
break;
}
}
示例11: createFile
function createFile($args)
{
list($plugin) = TranslatorHandler::validate();
TranslatorHandler::setupTemplate();
$locale = array_shift($args);
if (!Locale::isLocaleValid($locale)) {
Request::redirect(null, null, 'index');
}
$filename = urldecode(urldecode(array_shift($args)));
if (!TranslatorAction::isLocaleFile($locale, $filename)) {
Request::redirect(null, null, 'edit', $locale);
}
import('file.FileManager');
FileManager::copyFile(TranslatorAction::determineReferenceFilename($locale, $filename), $filename);
Request::redirectUrl(Request::getUserVar('redirectUrl'));
}
示例12: PKPUsageStatsLoader
/**
* Constructor.
* @param $argv array task arguments
*/
function PKPUsageStatsLoader($args)
{
$plugin = PluginRegistry::getPlugin('generic', 'usagestatsplugin');
/* @var $plugin UsageStatsPlugin */
$this->_plugin = $plugin;
$arg = current($args);
switch ($arg) {
case 'autoStage':
if ($plugin->getSetting(0, 'createLogFiles')) {
$this->_autoStage = true;
}
break;
case 'externalLogFiles':
$this->_externalLogFiles = true;
break;
}
// Define the base filesystem path.
$args[0] = $plugin->getFilesPath();
parent::FileLoader($args);
$this->_baseSystemUrl = Config::getVar('general', 'base_url');
$this->_baseSystemEscapedPath = str_replace('/', '\\/', parse_url($this->_baseSystemUrl, PHP_URL_PATH));
// Load the metric type constant.
PluginRegistry::loadCategory('reports');
import('classes.statistics.StatisticsHelper');
$statsHelper = new StatisticsHelper();
$geoLocationTool = $statsHelper->getGeoLocationTool();
$this->_geoLocationTool = $geoLocationTool;
$plugin->import('UsageStatsTemporaryRecordDAO');
$statsDao = new UsageStatsTemporaryRecordDAO();
DAORegistry::registerDAO('UsageStatsTemporaryRecordDAO', $statsDao);
$this->_counterRobotsListFile = $this->_getCounterRobotListFile();
$contextDao = Application::getContextDAO();
/* @var $contextDao ContextDAO */
$contextFactory = $contextDao->getAll();
/* @var $contextFactory DAOResultFactory */
$contextsByPath = array();
while ($context = $contextFactory->next()) {
/* @var $context Context */
$contextsByPath[$context->getPath()] = $context;
}
$this->_contextsByPath = $contextsByPath;
$this->checkFolderStructure(true);
if ($this->_autoStage) {
// Copy all log files to stage directory, except the current day one.
$fileMgr = new FileManager();
$logsDirFiles = glob($plugin->getUsageEventLogsPath() . DIRECTORY_SEPARATOR . '*');
$processingDirFiles = glob($this->getProcessingPath() . DIRECTORY_SEPARATOR . '*');
if (is_array($logsDirFiles) && is_array($processingDirFiles)) {
// It's possible that the processing directory have files that
// were being processed but the php process was stopped before
// finishing the processing. Just copy them to the stage directory too.
$dirFiles = array_merge($logsDirFiles, $processingDirFiles);
foreach ($dirFiles as $filePath) {
// Make sure it's a file.
if ($fileMgr->fileExists($filePath)) {
// Avoid current day file.
$filename = pathinfo($filePath, PATHINFO_BASENAME);
$currentDayFilename = $plugin->getUsageEventCurrentDayLogName();
if ($filename == $currentDayFilename) {
continue;
}
if ($fileMgr->copyFile($filePath, $this->getStagePath() . DIRECTORY_SEPARATOR . $filename)) {
$fileMgr->deleteFile($filePath);
}
}
}
}
}
}
示例13: create
public static function create($name, $location, $tie_teams)
{
global $lng;
$query = "INSERT INTO leagues (date, location, name, tie_teams) VALUES (NOW(), '" . mysql_real_escape_string($location) . "', '" . mysql_real_escape_string($name) . "', " . (int) $tie_teams . ")";
if (get_alt_col('leagues', 'name', $name, 'lid')) {
return $lng->getTrn('admin/nodes/errors/league_already_exists');
}
// Create the league
mysql_query($query);
// Make a new settings file for that league.
$new_lid = get_alt_col('leagues', 'name', $name, 'lid');
$settings_new_filename = FileManager::getSettingsDirectoryName() . "/settings_{$new_lid}.php";
$settings_template_filename = FileManager::getSettingsDirectoryName() . "/settings_new_league_template.php";
if (!FileManager::copyFile($settings_template_filename, $settings_new_filename)) {
return $lng->getTrn('admin/nodes/errors/settings_file_copy_failed');
}
return false;
}
示例14: autoStage
/**
* Auto stage usage stats log files, also moving files that
* might be in processing folder to stage folder.
*/
function autoStage()
{
$plugin = $this->_plugin;
// Copy all log files to stage directory, except the current day one.
$fileMgr = new FileManager();
$logFiles = array();
$logsDirFiles = glob($plugin->getUsageEventLogsPath() . DIRECTORY_SEPARATOR . '*');
// It's possible that the processing directory has files that
// were being processed but the php process was stopped before
// finishing the processing. Just copy them to the stage directory too.
$processingDirFiles = glob($this->getProcessingPath() . DIRECTORY_SEPARATOR . '*');
if (is_array($logsDirFiles)) {
$logFiles = array_merge($logFiles, $logsDirFiles);
}
if (is_array($processingDirFiles)) {
$logFiles = array_merge($logFiles, $processingDirFiles);
}
foreach ($logFiles as $filePath) {
// Make sure it's a file.
if ($fileMgr->fileExists($filePath)) {
// Avoid current day file.
$filename = pathinfo($filePath, PATHINFO_BASENAME);
$currentDayFilename = $plugin->getUsageEventCurrentDayLogName();
if ($filename == $currentDayFilename) {
continue;
}
if ($fileMgr->copyFile($filePath, $this->getStagePath() . DIRECTORY_SEPARATOR . $filename)) {
$fileMgr->deleteFile($filePath);
}
}
}
}
示例15: pathinfo
/**
* Copy the passed file, filtering entries
* related to this installation.
* @param $filePath string
*/
function _copyFile($filePath)
{
$usageStatsFiles = $this->_usageStatsFiles;
$usageStatsDir = $this->_usageStatsDir;
$tmpDir = $this->_tmpDir;
$fileName = pathinfo($filePath, PATHINFO_BASENAME);
$fileMgr = new FileManager();
$isCompressed = false;
$uncompressedFileName = $fileName;
if (pathinfo($filePath, PATHINFO_EXTENSION) == 'gz') {
$isCompressed = true;
$uncompressedFileName = substr($fileName, 0, -3);
}
if (in_array($uncompressedFileName, $usageStatsFiles)) {
printf(__('admin.copyAccessLogFileTool.warning.fileAlreadyExists', array('filePath' => $filePath)) . "\n");
return;
}
$tmpFilePath = $tmpDir . DIRECTORY_SEPARATOR . $fileName;
// Copy the file to a temporary directory.
if (!$fileMgr->copyFile($filePath, $tmpFilePath)) {
printf(__('admin.copyAccessLogFileTool.error.copyingFile', array('filePath' => $filePath, 'tmpFilePath' => $tmpFilePath)) . "\n");
exit(1);
}
// Uncompress it, if needed.
$gunzipPath = escapeshellarg(Config::getVar('cli', 'gunzip'));
if ($isCompressed) {
exec($gunzipPath . ' ' . $tmpFilePath);
$tmpFilePath = substr($tmpFilePath, 0, -3);
}
// Filter only entries that contains journal paths.
$egrepPath = escapeshellarg(Config::getVar('cli', 'egrep'));
$destinationPath = $usageStatsDir . DIRECTORY_SEPARATOR . FILE_LOADER_PATH_STAGING . DIRECTORY_SEPARATOR . pathinfo($tmpFilePath, PATHINFO_BASENAME);
// Each journal path is already escaped, see the constructor.
exec($egrepPath . " -i '" . $this->_journalPaths . "' " . escapeshellarg($tmpFilePath) . " > " . escapeshellarg($destinationPath));
if (!$fileMgr->deleteFile($tmpFilePath)) {
printf(__('admin.copyAccessLogFileTool.error.deletingFile', array('tmpFilePath' => $tmpFilePath)) . "\n");
exit(1);
}
printf(__('admin.copyAccessLogFileTool.success', array('filePath' => $filePath, 'destinationPath' => $destinationPath)) . "\n");
}