本文整理汇总了PHP中FileManager::copyDir方法的典型用法代码示例。如果您正苦于以下问题:PHP FileManager::copyDir方法的具体用法?PHP FileManager::copyDir怎么用?PHP FileManager::copyDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::copyDir方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upgradePlugin
/**
* Upgrade a plugin to a newer version from the user's filesystem
* @param $path string path to plugin Directory
* @param $templateMgr reference to template manager
* @param $category string
* @param $plugin string
* @return boolean
*/
function upgradePlugin($path, &$templateMgr, $category, $plugin)
{
$this->validate();
$versionFile = $path . VERSION_FILE;
$templateMgr->assign('error', true);
$templateMgr->assign('pageHierarchy', $this->setBreadcrumbs(true, $category));
$pluginVersion =& VersionCheck::getValidPluginVersionInfo($versionFile, $templateMgr);
if (is_null($pluginVersion)) {
return false;
}
assert(is_a($pluginVersion, 'Version'));
// Check whether the uploaded plug-in fits the original plug-in.
if ('plugins.' . $category != $pluginVersion->getProductType()) {
$templateMgr->assign('message', 'manager.plugins.wrongCategory');
return false;
}
if ($plugin != $pluginVersion->getProduct()) {
$templateMgr->assign('message', 'manager.plugins.wrongName');
return false;
}
$versionDao =& DAORegistry::getDAO('VersionDAO');
$installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProductType(), $pluginVersion->getProduct(), true);
if (!$installedPlugin) {
$templateMgr->assign('message', 'manager.plugins.pleaseInstall');
return false;
}
if ($this->_checkIfNewer($pluginVersion->getProductType(), $pluginVersion->getProduct(), $pluginVersion)) {
$templateMgr->assign('message', 'manager.plugins.installedVersionNewer');
return false;
} else {
$pluginDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $category . DIRECTORY_SEPARATOR . $plugin;
$pluginLibDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $category . DIRECTORY_SEPARATOR . $plugin;
// Delete existing files.
if (is_dir($pluginDest)) {
FileManager::rmtree($pluginDest);
}
if (is_dir($pluginLibDest)) {
FileManager::rmtree($pluginLibDest);
}
// Check whether deleting has worked.
if (is_dir($pluginDest) || is_dir($pluginLibDest)) {
$templateMgr->assign('message', 'manager.plugins.deleteError');
return false;
}
// Copy the plug-in from the temporary folder to the
// target folder.
// Start with the library part (if any).
$libPath = $path . DIRECTORY_SEPARATOR . 'lib';
if (is_dir($libPath)) {
if (!FileManager::copyDir($libPath, $pluginLibDest)) {
$templateMgr->assign('message', 'manager.plugins.copyError');
return false;
}
// Remove the library part of the temporary folder.
FileManager::rmtree($libPath);
}
// Continue with the application-specific part (mandatory).
if (!FileManager::copyDir($path, $pluginDest)) {
$templateMgr->assign('message', 'manager.plugins.copyError');
return false;
}
// Remove the temporary folder.
FileManager::rmtree(dirname($path));
$upgradeFile = $pluginDest . UPGRADE_FILE;
if (FileManager::fileExists($upgradeFile)) {
$params = $this->_setConnectionParams();
$installer = new Upgrade($params, $upgradeFile, true);
if (!$installer->execute()) {
$templateMgr->assign('message', array('manager.plugins.upgradeFailed', $installer->getErrorString()));
return false;
}
}
$installedPlugin->setCurrent(0);
$pluginVersion->setCurrent(1);
$versionDao->insertVersion($pluginVersion, true);
$templateMgr->assign('category', $category);
$templateMgr->assign('plugin', $plugin);
$templateMgr->assign('message', array('manager.plugins.upgradeSuccessful', $pluginVersion->getVersionString()));
$templateMgr->assign('uploaded', true);
$templateMgr->assign('error', false);
return true;
}
}
示例2: upgradePlugin
/**
* Upgrade a plugin to a newer version from the user's filesystem
* @param $path string path to plugin Directory
* @param $templateMgr reference to template manager
* @return boolean
*/
function upgradePlugin($path, &$templateMgr)
{
$this->validate();
$versionFile = $path . VERSION_FILE;
$templateMgr->assign('error', true);
$templateMgr->assign('path', 'upgrade');
$pluginVersion =& VersionCheck::getValidPluginVersionInfo($versionFile, $templateMgr);
if (is_null($pluginVersion)) {
return false;
}
assert(is_a($pluginVersion, 'Version'));
$versionDao =& DAORegistry::getDAO('VersionDAO');
$installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProduct(), true);
if (!$installedPlugin) {
$templateMgr->assign('message', 'manager.plugins.pleaseInstall');
return false;
}
if ($this->checkIfNewer($pluginVersion->getProduct(), $pluginVersion)) {
$templateMgr->assign('message', 'manager.plugins.installedVersionNewer');
return false;
} else {
$pluginDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . strtr($pluginVersion->getProductType(), '.', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $pluginVersion->getProduct();
FileManager::rmtree($pluginDest);
if (FileManager::fileExists($pluginDest, 'dir')) {
$templateMgr->assign('message', 'manager.plugins.deleteError');
return false;
}
if (!FileManager::copyDir($path, $pluginDest)) {
$templateMgr->assign('message', 'manager.plugins.copyError');
return false;
}
$upgradeFile = $pluginDest . UPGRADE_FILE;
if (FileManager::fileExists($upgradeFile)) {
$params = $this->setConnectionParams();
$installer = new Upgrade($params, $upgradeFile, true);
if (!$installer->execute()) {
$templateMgr->assign('message', array('manager.plugins.upgradeFailed', $installer->getErrorString()));
return false;
}
}
$installedPlugin->setCurrent(0);
$pluginVersion->setCurrent(1);
$versionDao->insertVersion($pluginVersion, true);
$templateMgr->assign('message', array('manager.plugins.upgradeSuccessful', $pluginVersion->getVersionString()));
$templateMgr->assign('uploaded', true);
$templateMgr->assign('error', false);
return true;
}
}
示例3: 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;
}
}
示例4: upgradePlugin
/**
* Upgrade a plugin to a newer version from the user's filesystem
* @param $category string
* @param $plugin string
* @param $path string path to plugin Directory
* @param $category string
* @param $plugin string
* @return Version|null The upgraded version, on success; null on fail
*/
function upgradePlugin($category, $plugin, $path, &$errorMsg)
{
$versionFile = $path . '/' . PLUGIN_VERSION_FILE;
$pluginVersion = VersionCheck::getValidPluginVersionInfo($versionFile, $errorMsg);
if (!$pluginVersion) {
return null;
}
// Check whether the uploaded plug-in fits the original plug-in.
if ('plugins.' . $category != $pluginVersion->getProductType()) {
$errorMsg = __('manager.plugins.wrongCategory');
return null;
}
if ($plugin != $pluginVersion->getProduct()) {
$errorMsg = __('manager.plugins.wrongName');
return null;
}
$versionDao = DAORegistry::getDAO('VersionDAO');
$installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProductType(), $pluginVersion->getProduct(), true);
if (!$installedPlugin) {
$errorMsg = __('manager.plugins.pleaseInstall');
return null;
}
if ($this->_checkIfNewer($pluginVersion->getProductType(), $pluginVersion->getProduct(), $pluginVersion)) {
$errorMsg = __('manager.plugins.installedVersionNewer');
return null;
} else {
$pluginDest = Core::getBaseDir() . '/plugins/' . $category . '/' . $plugin;
$pluginLibDest = Core::getBaseDir() . '/' . PKP_LIB_PATH . '/plugins/' . $category . '/' . $plugin;
// Delete existing files.
$fileManager = new FileManager();
if (is_dir($pluginDest)) {
$fileManager->rmtree($pluginDest);
}
if (is_dir($pluginLibDest)) {
$fileManager->rmtree($pluginLibDest);
}
// Check whether deleting has worked.
if (is_dir($pluginDest) || is_dir($pluginLibDest)) {
$errorMsg = __('message', 'manager.plugins.deleteError');
return null;
}
// Copy the plug-in from the temporary folder to the
// target folder.
// Start with the library part (if any).
$libPath = $path . '/lib';
if (is_dir($libPath)) {
if (!$fileManager->copyDir($libPath, $pluginLibDest)) {
$errorMsg = __('manager.plugins.copyError');
return null;
}
// Remove the library part of the temporary folder.
$fileManager->rmtree($libPath);
}
// Continue with the application-specific part (mandatory).
if (!$fileManager->copyDir($path, $pluginDest)) {
$errorMsg = __('manager.plugins.copyError');
return null;
}
// Remove the temporary folder.
$fileManager->rmtree(dirname($path));
$upgradeFile = $pluginDest . '/' . PLUGIN_UPGRADE_FILE;
if ($fileManager->fileExists($upgradeFile)) {
$params = $this->_getConnectionParams();
$installer = new Upgrade($params, $upgradeFile, true);
if (!$installer->execute()) {
$errorMsg = __('manager.plugins.upgradeFailed', array('errorString' => $installer->getErrorString()));
return null;
}
}
$installedPlugin->setCurrent(0);
$pluginVersion->setCurrent(1);
$versionDao->insertVersion($pluginVersion, true);
return $pluginVersion;
}
}
示例5: upgradePlugin
/**
* Upgrade a plugin to a newer version from the user's filesystem
* @param $path string path to plugin Directory
* @param $templateMgr reference to template manager
* @return boolean
*/
function upgradePlugin($path, &$templateMgr)
{
$versionFile = $path . VERSION_FILE;
$templateMgr->assign('error', true);
$templateMgr->assign('path', 'upgrade');
if (FileManager::fileExists($versionFile)) {
$versionInfo =& VersionCheck::parseVersionXML($versionFile);
} else {
$templateMgr->assign('message', 'manager.plugins.versionFileNotFound');
return false;
}
$pluginVersion = $versionInfo['version'];
$pluginName = $versionInfo['application'];
$category = explode(".", $pluginVersion->getProductType());
$versionDao =& DAORegistry::getDAO('VersionDAO');
$installedPlugin = $versionDao->getCurrentVersion($pluginName);
if (!$installedPlugin) {
$templateMgr->assign('message', 'manager.plugins.pleaseInstall');
return false;
}
if (PluginManagementHandler::checkIfNewer($pluginName, $pluginVersion)) {
$templateMgr->assign('message', 'manager.plugins.installedVersionNewer');
return false;
} else {
$pluginDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $category . DIRECTORY_SEPARATOR . $pluginName;
FileManager::rmtree($pluginDest);
if (FileManager::fileExists($pluginDest, 'dir')) {
$templateMgr->assign('message', 'manager.plugins.deleteError');
return false;
}
if (!FileManager::copyDir($path, $pluginDest)) {
$templateMgr->assign('message', 'manager.plugins.copyError');
return false;
}
$upgradeFile = $pluginDest . DIRECTORY_SEPARATOR . UPGRADE_FILE;
if (FileManager::fileExists($upgradeFile)) {
$params = PluginManagementHandler::setConnectionParams();
$installer = new Upgrade($params, $upgradeFile, true);
if (!$installer->execute()) {
$templateMgr->assign('message', array('manager.plugins.upgradeFailed', $installer->getErrorString()));
return false;
}
}
$installedPlugin->setCurrent(0);
$pluginVersion->setCurrent(1);
$versionDao->insertVersion($pluginVersion);
$templateMgr->assign('message', array('manager.plugins.upgradeSuccessful', $pluginVersion->getVersionString()));
$templateMgr->assign('uploaded', true);
$templateMgr->assign('error', false);
return true;
}
}