本文整理汇总了PHP中Includes\Utils\FileManager::isDirWriteable方法的典型用法代码示例。如果您正苦于以下问题:PHP FileManager::isDirWriteable方法的具体用法?PHP FileManager::isDirWriteable怎么用?PHP FileManager::isDirWriteable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Includes\Utils\FileManager
的用法示例。
在下文中一共展示了FileManager::isDirWriteable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateCustomImages
/**
* Update custom images
*
* @return void
*/
protected function updateCustomImages()
{
$dir = \XLite\Module\XC\ThemeTweaker\Main::getThemeDir() . 'images' . LC_DS;
if ($_FILES && $_FILES['new_images'] && $_FILES['new_images']['name']) {
if (!\Includes\Utils\FileManager::isExists($dir)) {
\Includes\Utils\FileManager::mkdirRecursive($dir);
}
if (\Includes\Utils\FileManager::isDirWriteable($dir)) {
foreach ($_FILES['new_images']['name'] as $i => $data) {
\Includes\Utils\FileManager::moveUploadedFileByMultiple('new_images', $i, $dir);
}
} else {
\XLite\Core\TopMessage::addError('The directory {{dir}} does not exist or is not writable.', array('dir' => $dir));
}
}
$delete = \XLite\Core\Request::getInstance()->delete;
if ($delete && is_array($delete)) {
foreach ($delete as $file => $del) {
if ($del) {
\Includes\Utils\FileManager::deleteFile($dir . $file);
}
}
}
}
示例2: uninstallModule
/**
* Uninstall module
*
* @param \XLite\Model\Module $module Module object
* @param array &$messages Messages list
*
* @return boolean
*/
public function uninstallModule(\XLite\Model\Module $module, &$messages)
{
$result = false;
// Get module pack
$pack = new \XLite\Core\Pack\Module($module);
$dirs = $pack->getDirs();
$nonWritableDirs = array();
// Check module directories permissions
foreach ($dirs as $dir) {
if (\Includes\Utils\FileManager::isExists($dir) && !\Includes\Utils\FileManager::isDirWriteable($dir)) {
$nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT);
}
}
$params = array('name' => sprintf('%s v%s (%s)', $module->getModuleName(), $module->getVersion(), $module->getAuthorName()));
if (empty($nonWritableDirs)) {
$yamlData = array();
$yamlFiles = \Includes\Utils\ModulesManager::getModuleYAMLFiles($module->getAuthor(), $module->getName());
foreach ($yamlFiles as $yamlFile) {
$yamlData[] = \Includes\Utils\FileManager::read($yamlFile);
}
if (!$module->checkModuleMainClass()) {
$classFile = LC_DIR_CLASSES . \Includes\Utils\Converter::getClassFile($module->getMainClass());
if (\Includes\Utils\FileManager::isFileReadable($classFile)) {
require_once $classFile;
}
}
// Call uninstall event method
$r = $module->callModuleMethod('callUninstallEvent', 111);
if (111 == $r) {
\XLite\Logger::getInstance()->log($module->getActualName() . ': Method callUninstallEvent() was not called');
}
// Remove from FS
foreach ($dirs as $dir) {
\Includes\Utils\FileManager::unlinkRecursive($dir);
}
\Includes\Utils\ModulesManager::disableModule($module->getActualName());
\Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName());
// Remove module from DB
try {
// Refresh module entity as it was changed by disableModule() method above
$module = $this->find($module->getModuleID());
$this->delete($module);
} catch (\Exception $e) {
$messages[] = $e->getMessage();
}
if ($module->getModuleID()) {
$messages[] = \XLite\Core\Translation::getInstance()->translate('A DB error occured while uninstalling the module X', $params);
} else {
if (!empty($yamlData)) {
foreach ($yamlData as $yaml) {
\XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml);
}
}
$messages[] = \XLite\Core\Translation::getInstance()->translate('The module X has been uninstalled successfully', $params);
$result = true;
}
} else {
$messages[] = \XLite\Core\Translation::getInstance()->translate('Unable to delete module X files: some dirs have no writable permissions: Y', $params + array('dirs' => implode(', ', $nonWritableDirs)));
}
return $result;
}
示例3: writeDataToFile
/**
* Write data from request into a file
*
* @param \PEAR2\HTTP\Request\Response $response Response to get data
*
* @return string
*/
protected function writeDataToFile(\PEAR2\HTTP\Request\Response $response)
{
if (!\Includes\Utils\FileManager::isDir(LC_DIR_TMP)) {
\Includes\Utils\FileManager::mkdir(LC_DIR_TMP);
}
if (!\Includes\Utils\FileManager::isDirWriteable(LC_DIR_TMP)) {
\Includes\ErrorHandler::fireError('Directory "' . LC_DIR_TMP . '" is not writeable');
}
$path = \Includes\Utils\FileManager::getUniquePath(LC_DIR_TMP, uniqid() . '.' . \Includes\Utils\PHARManager::getExtension() ?: 'tar');
return isset($response->body) && \Includes\Utils\FileManager::write($path, $response->body) ? $path : null;
}
示例4: deleteFileCallback
/**
* Callback for a common operation for upgrade
*
* @param string $path File short path
* @param boolean $isTestMode If in test mode
*
* @return void
*/
protected function deleteFileCallback($path, $isTestMode)
{
if ($isTestMode) {
if (!\Includes\Utils\FileManager::isDirWriteable($this->manageFile($path, 'getDir'))) {
$this->addFileErrorMessage('File\'s directory is not writable', $path, false);
$this->wrongPermissions[] = $this->manageFile($path, 'getDir');
}
} elseif ($this->manageFile($path, 'deleteFile')) {
$this->addFileInfoMessage('File is deleted', $path, true);
// Remove the parent directory if upgrade process removes all files in it
$dir = dirname($path);
if (\Includes\Utils\FileManager::isEmptyDir($dir)) {
\Includes\Utils\FileManager::unlinkRecursive($dir);
if (!\Includes\Utils\FileManager::isExists($dir)) {
$this->addFileInfoMessage('Directory is deleted', $dir, true);
} else {
$this->addFileInfoMessage('Unable to delete directory', $dir, true);
}
}
} else {
$this->addFileErrorMessage('Unable to delete file', $path, true);
}
}
示例5: doActionImport
/**
* Import action
*
* @return void
*/
protected function doActionImport()
{
foreach (\XLite\Logic\Import\Importer::getImportOptionsList() as $key) {
\XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('category' => 'Import', 'name' => $key, 'value' => isset(\XLite\Core\Request::getInstance()->options[$key]) ? \XLite\Core\Request::getInstance()->options[$key] : false));
}
\XLite\Core\Config::updateInstance();
$dirTo = LC_DIR_VAR . \XLite\Logic\Import\Importer::getImportDir();
if (!\Includes\Utils\FileManager::isExists($dirTo)) {
\Includes\Utils\FileManager::mkdirRecursive($dirTo);
}
$filesToImport = array();
if ($_FILES && isset($_FILES['files']) && $_FILES['files']['name'] && $_FILES['files']['name'][0] && \Includes\Utils\FileManager::isDirWriteable($dirTo)) {
$list = glob($dirTo . LC_DS . '*');
if ($list) {
foreach ($list as $path) {
if (is_file($path)) {
\Includes\Utils\FileManager::deleteFile($path);
}
}
}
$files = $_FILES['files'];
foreach ($files['name'] as $key => $name) {
$path = null;
if ($name && UPLOAD_ERR_OK === $files['error'][$key]) {
$path = \Includes\Utils\FileManager::getUniquePath($dirTo, $name ?: $files['name'][$key]);
if (move_uploaded_file($files['tmp_name'][$key], $path)) {
if (\XLite\Core\Archive::getInstance()->isArchive($path) || 'csv' == substr(strrchr($path, '.'), 1)) {
$filesToImport[] = $path;
} else {
\XLite\Core\TopMessage::addError('The "{{file}}" is not CSV or archive', array('file' => $name));
\Includes\Utils\FileManager::deleteFile($path);
}
} else {
$path = null;
}
}
if (!$path) {
\XLite\Core\TopMessage::addError('The "{{file}}" file was not uploaded', array('file' => $name));
}
}
}
if ($filesToImport) {
\XLite\Logic\Import\Importer::run(\XLite\Logic\Import\Importer::assembleImportOptions() + array('files' => $filesToImport));
}
}
示例6: doActionUninstall
/**
* Uninstall module
*
* @return void
*/
protected function doActionUninstall()
{
$module = $this->getModule();
if ($module) {
$pack = new \XLite\Core\Pack\Module($module);
$dirs = $pack->getDirs();
$nonWritableDirs = array();
// Check permissions
foreach ($dirs as $dir) {
if (!\Includes\Utils\FileManager::isDirWriteable($dir)) {
$nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT);
}
}
$params = array('name' => $module->getActualName());
if (empty($nonWritableDirs)) {
$yaml = \Includes\Utils\FileManager::read(\Includes\Utils\ModulesManager::getModuleYAMLFile($module->getAuthor(), $module->getName()));
// Remove from FS
foreach ($dirs as $dir) {
\Includes\Utils\FileManager::unlinkRecursive($dir);
}
// Disable this and depended modules
\Includes\Utils\ModulesManager::disableModule($module->getActualName());
\Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName());
// Remove from DB
\XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->delete($module);
if ($module->getModuleID()) {
$message = 'A DB error occured while uninstalling the module "{{name}}"';
$this->showError(__FUNCTION__, $message, $params);
} else {
if (!empty($yaml)) {
\XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml);
}
$message = 'The module "{{name}}" has been uninstalled successfully';
$this->showInfo(__FUNCTION__, $message, $params);
}
// To restore previous state
\XLite\Core\Marketplace::getInstance()->saveAddonsList(0);
// Flag to rebuild cache
\XLite::setCleanUpCacheFlag(true);
} else {
$message = 'Unable to delete module "{{name}}" files: some dirs have no writable permissions: {{dirs}}';
$this->showError(__FUNCTION__, $message, $params + array('dirs' => implode(', ', $nonWritableDirs)));
}
}
}
示例7: checkPermissions
/**
* Check directory permissions and try to correct them
*
* @param string $dir Path to check
*
* @return void
*/
protected static function checkPermissions($dir)
{
\Includes\Utils\FileManager::mkdirRecursive($dir);
if (!\Includes\Utils\FileManager::isDirWriteable($dir)) {
@\Includes\Utils\FileManager::chmod($dir, static::getDirDefaultPermissions($dir));
if (!\Includes\Utils\FileManager::isDirWriteable($dir)) {
static::fireDirPermissionsError($dir);
}
}
}
示例8: deleteFileCallback
/**
* Callback for a common operation for upgrade
*
* @param string $path File short path
* @param boolean $isTestMode If in test mode
*
* @return void
*/
protected function deleteFileCallback($path, $isTestMode)
{
if ($isTestMode) {
if (!\Includes\Utils\FileManager::isDirWriteable($this->manageFile($path, 'getDir'))) {
$this->addFileErrorMessage('File\'s directory is not writable', $path, false);
}
} elseif ($this->manageFile($path, 'deleteFile')) {
$this->addFileInfoMessage('File is deleted', $path, true);
} else {
$this->addFileErrorMessage('Unable to delete file', $path, true);
}
}
示例9: download
/**
* Download pack
*
* @param \XLite\Core\Pack\APack $pack Files to pack
* @param boolean $compress Flag OPTIONAL
*
* @return void
*/
protected static function download(\XLite\Core\Pack\APack $pack, $compress = true)
{
if (!\Includes\Utils\FileManager::isDir(LC_DIR_TMP)) {
\Includes\Utils\FileManager::mkdir(LC_DIR_TMP);
}
if (!\Includes\Utils\FileManager::isDirWriteable(LC_DIR_TMP)) {
\Includes\ErrorHandler::fireError('Directory "' . LC_DIR_TMP . '" is not writeable');
}
$path = LC_DIR_TMP . $pack->getName() . '.tar';
$phar = static::pack($path, $pack->getDirectoryIterator(), $pack->getMetadata(), $compress);
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . basename($path) . '"');
header('Content-Length: ' . filesize($path));
echo \Includes\Utils\FileManager::read($path);
\Includes\Utils\FileManager::deleteFile($path);
exit(0);
}
示例10: isDirExists
/**
* isDirExists
*
* @return boolean
*/
public function isDirExists()
{
if (!is_dir(LC_DIR_BACKUP)) {
\Includes\Utils\FileManager::mkdirRecursive(LC_DIR_BACKUP);
}
return \Includes\Utils\FileManager::isDirWriteable(LC_DIR_BACKUP);
}