public function preparePage() { $this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager); $this->P->cb_pagetype = 'content'; $this->P->cb_subnav = 'admin'; $this->P->oPayload->cl_html = 'The template cache has been cleared.'; $adapter = new \League\Flysystem\Adapter\Local(PATH_CACHE); $filesystem = new \League\Flysystem\Filesystem($adapter); $filesystem->deleteDir(DIRNAME_TEMPLATECACHE); $filesystem->createDir(DIRNAME_TEMPLATECACHE); }
/** * execute command * * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $subfolder = $input->getOption('subfolder'); if ($subfolder == null) { $output->writeln('<error>Sorry, you did not enter cache sub folder name.</error>'); unset($subfolder); return false; } if ($subfolder != null) { $Cache = new \System\Libraries\Cache(); $cache_config = $Cache->getCacheConfig(); $style = new \Symfony\Component\Console\Formatter\OutputFormatterStyle('white', 'green'); $output->getFormatter()->setStyle('success', $style); unset($style); if ($subfolder == '*') { // entered command to delete all cache. $Cache->deleteAllFile(); $output->writeln('<success>All cache was deleted successfully.</success>'); } else { if (is_array($cache_config) && array_key_exists('driver', $cache_config) && $cache_config['driver'] == 'Filesystem' && array_key_exists('cache_path', $cache_config)) { $adapter = new \League\Flysystem\Adapter\Local($cache_config['cache_path']); $Filesystem = new \League\Flysystem\Filesystem($adapter); $Filesystem->addPlugin(new \League\Flysystem\Plugin\ListPaths()); try { $Filesystem->getMetadata($subfolder); // selected sub folder exists. $Cache->setSubFolder($subfolder); $Cache->deleteAllFile(); unset($Filesystem); $output->writeln('<success>The cache inside "' . $subfolder . '" folder was deleted successfully.</success>'); } catch (\Exception $e) { $output->writeln('<error>The "' . $subfolder . '" cache folder is not found.</error>'); } unset($adapter, $Filesystem); } } unset($Cache, $cache_config); } unset($subfolder); }
/** * setup configuration for Doctrine ORM * * @param array $db_config array config for override the default configuration. */ public function setupConfigurationOrm(array $db_config = []) { // setup entity paths. // @todo [cms][modules] load models path from modules folder where module is enabled on certain site in db. Pending: decide to use Doctrine ORM or Spot ORM first. $paths = []; $fs = new \League\Flysystem\Filesystem(new \League\Flysystem\Adapter\Local(MODULE_PATH)); $modules = $fs->listContents(); if (is_array($modules)) { foreach ($modules as $module) { if (is_array($module) && array_key_exists('path', $module)) { $module_dirs = $fs->listContents($module['path']); if (is_array($module_dirs)) { foreach ($module_dirs as $module_dir) { if (is_array($module_dir) && array_key_exists('type', $module_dir) && $module_dir['type'] == 'dir' && array_key_exists('path', $module_dir) && array_key_exists('basename', $module_dir) && $module_dir['basename'] == 'Models') { $paths[] = MODULE_PATH . DS . $module_dir['path']; } } // endforeach; unset($module_dir); } unset($module_dirs); } } // endforeach; unset($module); } unset($fs, $modules); // setup isDevmode. $config = new SystemConfig(); $config->load('app'); $is_devMode = $config->get('debug', 'app'); //setup connection configuration. if (empty($db_config)) { $config->load('db'); $db_params = $config->get('ALL', 'db'); $table_prefix = $db_params['table_prefix']; unset($config, $db_params['table_prefix']); } else { // incase that there is overriden configuration. $db_params = $db_config; if (is_array($db_config)) { if (array_key_exists('table_prefix', $db_config)) { $table_prefix = $db_config['table_prefix']; } if (array_key_exists('table_siteid_prefix', $db_config)) { $table_siteid_prefix = $db_config['table_siteid_prefix']; } } unset($db_params['table_prefix'], $db_params['table_siteid_prefix']); } $evm = new EventManager(); $table_prefix_class = new TablePrefix($table_prefix, isset($table_siteid_prefix) ? $table_siteid_prefix : ''); $evm->addEventListener(Events::loadClassMetadata, $table_prefix_class); unset($table_prefix, $table_prefix_class); $doctrine_config = Setup::createAnnotationMetadataConfiguration($paths, $is_devMode); $doctrine_config->setSQLLogger(new \System\Libraries\Db\Logger()); $this->EntityManager = EntityManager::create($db_params, $doctrine_config, $evm); unset($db_params, $doctrine_config, $evm, $is_devMode); }
/** * due to Doctrine cache deleteAll() cannot really delete file/folder for FilesystemCache, it just left old cache file and create new cache folder.<br> * this method is for really delete all cache and all file (in specified sub folder if it was set). * * @return boolean */ public function deleteAllFile() { $result = $this->deleteAll(); if (isset($this->cache_config['driver']) && $this->cache_config['driver'] == 'Filesystem' && isset($this->cache_config['cache_path'])) { $adapter = new \League\Flysystem\Adapter\Local($this->cache_config['cache_path']); $Filesystem = new \League\Flysystem\Filesystem($adapter); $Filesystem->addPlugin(new \League\Flysystem\Plugin\ListPaths()); if ($this->cache_config['cache_path'] . $this->subFolder == STORAGE_PATH . DS . 'cms' . DS . 'cache') { // sub folder may not set and cache path is match main cache folder. $files = $Filesystem->listPaths($this->subFolder); if (is_array($files)) { foreach ($files as $file) { if ($file != '.gitignore' && is_dir($this->cache_config['cache_path'] . $this->subFolder . '/' . $file)) { $Filesystem->deleteDir($file); } elseif ($file != '.gitignore' && is_file($this->cache_config['cache_path'] . $this->subFolder . '/' . $file)) { $Filesystem->delete($file); } } unset($file); } unset($files); } else { // sub folder is set. $files = $Filesystem->listPaths(''); if (is_array($files)) { foreach ($files as $file) { if (is_dir($this->cache_config['cache_path'] . '/' . $file)) { $Filesystem->deleteDir($file); } elseif (is_file($this->cache_config['cache_path'] . '/' . $file)) { $Filesystem->delete($file); } } unset($file); } unset($files); } } return $result; }
/** * Delete the profile picture of the user. * * @param int $userId * @param string $mediaFolder * @param League\Flysystem\Filesystem $filesystem * * @throws Exception */ public function removeImage($userId, $mediaFolder, $filesystem) { $row = $this->getTable(); $row->load(array('user_id' => $userId)); if ((int) $row->get('id') > 0) { // Delete the profile pictures. if ($row->get('image') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image'))) { $filesystem->delete($mediaFolder . '/' . $row->get('image')); } if ($row->get('image_small') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image_small'))) { $filesystem->delete($mediaFolder . '/' . $row->get('image_small')); } if ($row->get('image_square') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image_square'))) { $filesystem->delete($mediaFolder . '/' . $row->get('image_square')); } if ($row->get('image_icon') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image_icon'))) { $filesystem->delete($mediaFolder . '/' . $row->get('image_icon')); } $row->set('image', ''); $row->set('image_small', ''); $row->set('image_square', ''); $row->set('image_icon', ''); $row->store(); } }
function loadGitLabUser($log) { $filesystem = new \League\Flysystem\Filesystem(new \League\Flysystem\Adapter\Local(__DIR__)); if ($filesystem->has(USER_LIST)) { $users = $filesystem->read(USER_LIST); return json_decode($users); } return createUserList(USER_LIST); }
/** * Delete the images. * * @param JTable $row * @param string $mediaFolder * @param League\Flysystem\Filesystem $filesystem */ protected function deleteImages($row, $mediaFolder, $filesystem) { // Delete the profile pictures. if ($row->get('image') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image'))) { $filesystem->delete($mediaFolder . '/' . $row->get('image')); } if ($row->get('image_small') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image_small'))) { $filesystem->delete($mediaFolder . '/' . $row->get('image_small')); } if ($row->get('image_square') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image_square'))) { $filesystem->delete($mediaFolder . '/' . $row->get('image_square')); } if ($row->get('image_icon') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image_icon'))) { $filesystem->delete($mediaFolder . '/' . $row->get('image_icon')); } }
#!/usr/bin/php <?php $config = ['git_urls' => ['https://github.com/yfix/flysystem.git' => 'flysystem/'], 'autoload_config' => ['flysystem/src/' => 'League\\Flysystem'], 'example' => function () { $filesystem = new League\Flysystem\Filesystem(new League\Flysystem\Adapter\Local(__DIR__)); foreach ($filesystem->listContents() as $p) { echo $p['path'] . PHP_EOL; } }]; if ($return_config) { return $config; } require_once __DIR__ . '/_yf_autoloader.php'; new yf_autoloader($config);
/** * Remove a directory even if it's not empty. * * @param string $dir * @deprecated Use Flysystem instead. */ public static function rrmdir($dir) { $adapter = new Local(dirname($dir)); $filesystem = new \League\Flysystem\Filesystem($adapter); $filesystem->deleteDir(basename($dir)); }
/** * Checks to see if the filename is in filesystem file list. * * @since 1.0.0 * @param League\Flysystem\Filesystem $filesystem The filesystem object * @param string $filename The filename * @access public * @return boolean Returns true if file was found otherwise false */ public function filename_in_filesystem($filesystem, $filename) { //Iterate each file in the remote cloud and check if the filename of the //$file is in this list, if so then its found, otherwise not foreach ($filesystem->listContents(DIRECTORY_SEPARATOR, FALSE) as $file) { if ($file['basename'] === $filename) { return TRUE; } } return FALSE; }
public static function getOriginalFilePathByJobseekerId($filter) { $basePath = Factory::getSlimApp()->getContainer()["uploadConfig"]["path"]; $personalData = static::getDataFromDb("personal_information", $filter); if ($personalData) { $uploadId = $personalData["upload_id"]; $uploadData = static::getDataFromDb("upload", ["id" => $uploadId]); $fileName = $uploadId . "." . $uploadData["ftype"]; $basePath .= (string) round($uploadId, -4) . DS; $adapter = new \League\Flysystem\Adapter\Local($basePath); $fileManager = new \League\Flysystem\Filesystem($adapter); $fileExists = $fileManager->has($fileName); if ($fileExists) { $contents = $fileManager->read($fileName); $mime = $fileManager->getMimetype($fileName); $size = $fileManager->getSize($fileName); $originalName = $uploadData["name"]; return ["success" => true, "content" => $contents, "mime" => $mime, "size" => $size, "name" => $originalName]; } else { return ["success" => false, "message" => "File not found.", "error" => 1]; } } else { return ["success" => false, "message" => "Id is not recognized.", "error" => 1]; } }