예제 #1
1
 /**
  * backup single database table to file
  *
  * @param string $table
  * @param string $path
  */
 public function backupTableToFile(string $table, string $path)
 {
     $sql = $this->getHeader();
     $sql .= $this->backupTable($table);
     FileSystem::createDir($path);
     $path .= '/' . $table . '_' . date('Y-m-d_H-i-s') . '.sql';
     FileSystem::write($path, $sql);
 }
 private function createAndReturnTempDir() : string
 {
     $tempDir = sys_get_temp_dir() . '/php7_codesniffer';
     FileSystem::delete($tempDir);
     FileSystem::createDir($tempDir);
     return $tempDir;
 }
예제 #3
0
 /**
  * @param string $file
  */
 public function unlinkFile($file)
 {
     if (empty($file) && !is_file($file)) {
         return;
     }
     FileSystem::delete($file);
     $dir1 = dirname($file);
     $isEmpty = !(new \FilesystemIterator($dir1))->valid();
     if (!$isEmpty) {
         return;
     }
     FileSystem::delete($dir1);
     $dir2 = dirname($dir1);
     $isEmpty = !(new \FilesystemIterator($dir2))->valid();
     if (!$isEmpty) {
         return;
     }
     FileSystem::delete($dir2);
     $dir3 = dirname($dir2);
     $isEmpty = !(new \FilesystemIterator($dir3))->valid();
     if (!$isEmpty) {
         return;
     }
     FileSystem::delete($dir3);
 }
예제 #4
0
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults);
     if (!$config['token']) {
         throw new FioException('Token is required');
     }
     if (!$config['account']) {
         throw new FioException('Account is required');
     }
     Utils\FileSystem::createDir($config['temp']);
     // XMLFile
     $builder->addDefinition($this->prefix('xmlFile'))->setClass('h4kuna\\Fio\\Request\\Pay\\XMLFile')->setArguments(array($config['temp']));
     // PaymentFactory
     $builder->addDefinition($this->prefix('paymentFactory'))->setClass('h4kuna\\Fio\\Request\\Pay\\PaymentFactory')->setArguments(array($config['account']));
     // Queue
     $builder->addDefinition($this->prefix('queue'))->setClass('h4kuna\\Fio\\Request\\Queue')->setArguments(array($config['temp']));
     // Context
     $builder->addDefinition($this->prefix('context'))->setClass('h4kuna\\Fio\\Utils\\Context')->setArguments(array($config['token']));
     // StatementFactory
     $builder->addDefinition($this->prefix('statementFactory'))->setClass('h4kuna\\Fio\\Response\\Read\\JsonStatementFactory')->setArguments(array($config['transactionClass']));
     // FioPay
     $builder->addDefinition($this->prefix('fioPay'))->setClass('h4kuna\\Fio\\FioPay');
     // FioRead
     $builder->addDefinition($this->prefix('fioRead'))->setClass('h4kuna\\Fio\\FioRead')->setArguments(array($this->prefix('@context')));
 }
예제 #5
0
 /**
  * @param string $directory
  */
 public function __construct($directory)
 {
     Nette\Utils\SafeStream::register();
     $directory = rtrim($directory, DIRECTORY_SEPARATOR);
     FileSystem::createDir($directory);
     $this->directory = $directory;
 }
예제 #6
0
 function init()
 {
     parent::init();
     if (!$this->app->auth->isLoggedIn()) {
         return;
     }
     if (!$_GET['xepan-tool-to-clone']) {
         return $this->add('View')->set('Please select a tool');
     }
     $tool = $this->add($_GET['xepan-tool-to-clone']);
     if (!$tool->teplateOverridable) {
         $this->add('View')->set('You cannot override template for this tool');
         return;
     }
     $original_path = $tool->template->origin_filename;
     $tool->destroy();
     $specific_path = substr($original_path, strpos($original_path, '/templates/') + strlen('/templates/'));
     $override_path = $this->app->pathfinder->base_location->base_path . '/websites/' . $this->app->current_website_name . '/www/' . $specific_path;
     if (file_exists($override_path)) {
         $this->add('View')->set('File allrealy overrided at "' . $specific_path . '", Please remove this file and click again to reset');
         return;
     }
     $fs = \Nette\Utils\FileSystem::copy($original_path, $override_path, true);
     $this->add('View')->set('Tool template is overrided at "' . $specific_path . '", PLease use file manager in admin to edit file');
 }
예제 #7
0
 public function loadConfiguration()
 {
     parent::loadConfiguration();
     $builder = $this->getContainerBuilder();
     $cacheDir = $builder->parameters[self::CACHE_DIR];
     $imagesDir = $builder->parameters[self::IMAGES_DIR];
     $servicesCacheDir = $cacheDir . "services";
     $moduleCacheDir = $servicesCacheDir . "/" . $this->getModuleName();
     if (!file_exists($servicesCacheDir)) {
         try {
             FileSystem::createDir($servicesCacheDir);
         } catch (Nette\IOException $ex) {
             throw new Exceptions\InsufficientPermissionException("Permission denied while creating {$servicesCacheDir} directory");
         }
     }
     if (!file_exists($moduleCacheDir)) {
         try {
             FileSystem::createDir($moduleCacheDir);
         } catch (Nette\IOException $ex) {
             throw new Exceptions\InsufficientPermissionException("Permission denied while creating {$moduleCacheDir} directory");
         }
     }
     if (!file_exists($imagesDir)) {
         try {
             FileSystem::createDir($imagesDir);
         } catch (Nette\IOException $ex) {
             throw new Exceptions\InsufficientPermissionException("Permission denied while creating {$imagesDir} directory");
         }
     }
 }
예제 #8
0
 /**
  * @param string $imageName image name is comprised of UUID and original name (UUID/origName.extension)
  * @throws DBALException
  * @throws FileRemovalException
  */
 public function removeImage($imageName)
 {
     $id = mb_substr($imageName, 0, mb_strpos($imageName, '/'));
     $file = sprintf('%s/%s', $this->imageFileRoot, $imageName);
     try {
         $this->em->beginTransaction();
         $d = $this->em->createQuery('DELETE ' . Image::class . ' i WHERE i.id = :id')->execute(['id' => $id]);
         $directory = sprintf('%s/%s', $this->imageFileRoot, $id);
         // checks whether directory exists (each directory has always one file)
         if ($d > 0 and \file_exists($directory) and is_dir($directory)) {
             $r = \unlink($file);
             // and if so then remove file in it
             if ($r === false) {
                 // file couldn't be removed
                 $this->em->rollback();
                 $this->em->close();
                 throw new FileRemovalException();
             } else {
                 // remove directory
                 FileSystem::delete($directory);
             }
         }
         $this->em->commit();
     } catch (DBALException $e) {
         $this->em->rollback();
         $this->em->close();
         throw $e;
     }
 }
예제 #9
0
 public function wipeCache()
 {
     $paths = [realpath($this->tempDir . '/cache'), realpath($this->tempDir . '/proxy')];
     foreach (Nette\Utils\Finder::find('*')->in($paths) as $k => $file) {
         Nette\Utils\FileSystem::delete($k);
     }
 }
예제 #10
0
 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults);
     if (!$config['accounts']) {
         $config['accounts']['default'] = ['account' => $config['account'], 'token' => $config['token']];
     }
     unset($config['account'], $config['token']);
     Utils\FileSystem::createDir($config['temp']);
     // AccountCollection
     $builder->addDefinition($this->prefix('accounts'))->setClass('h4kuna\\Fio\\Account\\AccountCollection')->setFactory('h4kuna\\Fio\\Account\\AccountCollectionFactory::create', [$config['accounts']]);
     // XMLFile - lazy
     $builder->addDefinition($this->prefix('xmlFile'))->setClass('h4kuna\\Fio\\Request\\Pay\\XMLFile')->setArguments([$config['temp']]);
     // Queue
     $queue = $builder->addDefinition($this->prefix('queue'))->setClass('h4kuna\\Fio\\Request\\Queue');
     if ($config['downloadOptions']) {
         $setup = new \Nette\DI\Statement('?->setDownloadOptions(?)', [$queue, $config['downloadOptions']]);
         $queue->setSetup([$setup]);
     }
     // JsonTransactionFactory - lazy
     $builder->addDefinition($this->prefix('jsonTransactionFactory'))->setClass('h4kuna\\Fio\\Response\\Read\\JsonTransactionFactory')->setArguments([$config['transactionClass']]);
     // Reader - lazy
     $builder->addDefinition($this->prefix('reader'))->setClass('h4kuna\\Fio\\Request\\Read\\Files\\Json');
     // FioFactory
     $builder->addDefinition($this->prefix('fioFactory'))->setClass('h4kuna\\Fio\\Nette\\FioFactory');
 }
예제 #11
0
 /**
  * @inheritdoc
  */
 protected function copyToBinFolder($binDir)
 {
     FileSystem::createDir($binDir);
     $source = $this->targetDir . '/bin/casperjs';
     $target = $binDir . '/casperjs';
     Cli::makeSymbolicLink($source, $target);
 }
예제 #12
0
 /**
  * @param string $root
  * @return $this
  */
 public function setRoot($root)
 {
     if (!file_exists($root)) {
         Nette\Utils\FileSystem::createDir($root);
     }
     $this->root = realpath($root);
     return $this;
 }
 /**
  * @param string $oldIdGallery
  * @param string $newIdGallery
  * @param string $oldLang
  * @param string $newLang
  */
 public function renameGallery($oldIdGallery, $newIdGallery, $oldLang, $newLang)
 {
     b($oldIdGallery, 'oI');
     b($newIdGallery, 'nI');
     b($oldLang, 'oL');
     b($newLang, 'nL');
     FileSystem::rename(galleryPath . $oldIdGallery . '_' . $oldLang, galleryPath . $newIdGallery . '_' . $newLang);
 }
 /**
  * @param string $cacheStoragePath
  * @return Cache
  */
 protected function create($cacheStoragePath)
 {
     if (!file_exists($cacheStoragePath)) {
         FileSystem::createDir($cacheStoragePath);
     }
     $journal = new SQLiteJournal($this->storagePath . '/cached-pdfs-journal');
     $fileStorage = new FileStorage($cacheStoragePath, $journal);
     return new Cache($fileStorage, 'cached-pdfs');
 }
예제 #15
0
파일: Magic.php 프로젝트: jedenweb/plupload
 /**
  * @return Magic  provides fluent interface
  */
 public function cast()
 {
     Nette\Utils\FileSystem::createDir($this->fullPath);
     if (!file_exists($this->fullPath . '/copied')) {
         Nette\Utils\FileSystem::copy(__DIR__ . '/resources', $this->fullPath);
     }
     $this->useMagic = TRUE;
     return $this;
 }
예제 #16
0
 protected function processImageUpload(Nette\Http\FileUpload $upload, $targetDir, $id)
 {
     $dir = 'upload' . DIRECTORY_SEPARATOR . $targetDir . DIRECTORY_SEPARATOR . $id;
     if (!file_exists($this->rootDir . DIRECTORY_SEPARATOR . $dir)) {
         Nette\Utils\FileSystem::createDir($this->rootDir . DIRECTORY_SEPARATOR . $dir);
     }
     $path = $dir . DIRECTORY_SEPARATOR . $upload->getSanitizedName();
     $upload->move($this->rootDir . DIRECTORY_SEPARATOR . $path);
     return $path;
 }
예제 #17
0
 public function deleteExperiment($experimentId)
 {
     try {
         $experiment = $this->getExperimentById($experimentId);
         \Nette\Utils\FileSystem::delete(__DIR__ . '/../../data/' . $experiment['url_key']);
         return $this->db->table('experiments')->wherePrimary($experimentId)->delete();
     } catch (\Exception $exception) {
         return FALSE;
     }
 }
예제 #18
0
 /**
  * Store basic file.
  * For use in nette see *storeNetteFile*
  *
  * @param $sourceFile
  * @param $orginalName
  * @param bool $deleteOrginalFile
  * @return mixed
  * @throws \Nette\IOException
  */
 public function store($sourceFile, $orginalName, $deleteOrginalFile = false)
 {
     $path = $this->processStorePath($this->storePath, $orginalName);
     $thumbs = $this->createThumbs($sourceFile);
     $identifier = $this->backend->save($sourceFile, $orginalName, $path, $thumbs);
     if ($deleteOrginalFile) {
         FileSystem::delete($sourceFile);
     }
     return $identifier;
 }
예제 #19
0
 /**
  * @param Nette\Application\UI\Form $form
  * @param                           $values
  */
 public function deleteFormSubmitted(Nette\Application\UI\Form $form, $values)
 {
     if ($this->fileManager->isFeatureEnabled('deleteFile') && $form->submitted === $form['delete']) {
         $name = self::getPath($this, $values->file);
         Nette\Utils\FileSystem::delete($name);
         $this->onFileDelete($name);
         $this->flashMessage('fileManager.alert.fileDeleted', 'success');
     }
     $this->fileList->go('this', ['view' => 'Default']);
 }
예제 #20
0
 /**
  * @param Nette\Application\UI\Form $form
  * @param                           $values
  */
 public function createFormSubmitted(Nette\Application\UI\Form $form, $values)
 {
     if ($this->fileManager->isFeatureEnabled('createDir') && $form->submitted === $form['create']) {
         $dir = self::getPath($this, $values->name);
         Nette\Utils\FileSystem::createDir($dir, $this->createDirPermissions);
         $this->onDirCreate($dir);
         $this->flashMessage('fileManager.alert.dirCreated', 'success');
     }
     $this->directoryList->go('this', ['view' => 'Default']);
 }
 /**
  * @param Photoset $photoset
  * @param boolean $noSlug
  * @param boolean $dryRun
  * @param string $dir
  * @param boolean $cleanDir
  * @return string
  */
 private function managePhotosetDir(Photoset $photoset, $noSlug, $dryRun, $dir, $cleanDir)
 {
     $dirName = $this->dirnameCreator->create($photoset, $dir, $noSlug);
     if ($cleanDir && is_dir($dirName) && !$dryRun) {
         \Nette\Utils\FileSystem::delete($dirName);
     }
     if (!is_dir($dirName) && !$dryRun) {
         \Nette\Utils\FileSystem::createDir($dirName);
     }
     return $dirName;
 }
 /**
  * @param array $parameters
  * @throws DuplicationException
  */
 public function generate(array $parameters)
 {
     $mandatoryParameters = ['Name' => 'name'];
     $this->checkParameters($parameters, $mandatoryParameters);
     $finalDir = $this->config['componentsDir'] . '/' . $parameters['name'];
     if (is_dir($finalDir)) {
         throw new DuplicationException(sprintf('Component `%s` already exists.', $finalDir));
     }
     Nette\Utils\FileSystem::copy($this->config['templateDir'], $finalDir);
     $this->generateFiles($finalDir, $parameters);
 }
예제 #23
0
 /**
  * @param Utils\Image|string $sourceFile
  * @param string $name
  * @param string $resolution
  * @param int $method
  * @return ImagePath
  */
 public function saveFile($sourceFile, $name, $resolution, $method)
 {
     $filename = $this->path->getFilesystem($name, $resolution, $method);
     Utils\FileSystem::createDir(dirname($filename));
     if ($sourceFile instanceof Utils\Image) {
         $resolutionArray = explode('x', $resolution);
         $sourceFile->resize($resolutionArray[0], $resolutionArray[1], (int) $method)->save($filename);
     } elseif (!$this->download->save($sourceFile, $filename)) {
         throw new ImageManager\RemoteFileDoesNotExistsException($sourceFile);
     }
     return new ImagePath($this->getPathUrl($name, $resolution, $method), $filename);
 }
예제 #24
0
 /**
  * PdfGenerator constructor.
  *
  * @param $documentStorage
  * @param $tempDir
  */
 public function __construct($documentStorage, $tempDir)
 {
     define("_MPDF_TEMP_PATH", $tempDir . "/cache/mPdf/tmp/");
     define('_MPDF_TTFONTDATAPATH', $tempDir . "/cache/mPdf/ttfontdata/");
     $this->documentStorage = $documentStorage;
     if (!file_exists(_MPDF_TEMP_PATH)) {
         FileSystem::createDir(_MPDF_TEMP_PATH);
     }
     if (!file_exists(_MPDF_TTFONTDATAPATH)) {
         FileSystem::createDir(_MPDF_TTFONTDATAPATH);
     }
 }
예제 #25
0
 /**
  * @param Utils\Image $image
  * @param string $path
  * @param string $extension
  * @return Image
  */
 public function saveImage(Utils\Image $image, $path, $extension)
 {
     do {
         $relativePath = self::addSlashPath($path) . md5(microtime()) . '.' . strtolower($extension);
         $filename = $this->path->getSourceDir($relativePath);
     } while (is_file($filename));
     if ($this->maxSize) {
         $image->resize($this->maxSize['width'], $this->maxSize['height'], Utils\Image::SHRINK_ONLY);
     }
     Utils\FileSystem::createDir(dirname($filename));
     $image->save($filename);
     return new Image($this->path->getSourceDir(''), $relativePath);
 }
예제 #26
0
 public function compileConfig()
 {
     $repositories = $this->getAll();
     $domain = $this->httpRequest->getUrl()->getHostUrl();
     $config = ['homepage' => $domain, 'repositories' => []];
     foreach ($this->parameters as $property => $value) {
         $config[$property] = $value;
     }
     foreach ($repositories as $repository) {
         $config['repositories'][] = ['type' => $repository->type, 'url' => $repository->url];
     }
     $json = Json::encode($config, Json::PRETTY);
     FileSystem::write($this->configFile, $json);
 }
 private function handleInvalidation(Listing $listing)
 {
     $cache = $this->cacheFactory->getCache($listing->user->id, $listing->year);
     // removal of all generated pdf files of given Listing
     $generatedFiles = $cache->load('generatedPdfFilesByListing/' . $listing->getId());
     if ($generatedFiles !== null) {
         foreach ($generatedFiles as $key => $filePath) {
             if (!is_dir($filePath) and file_exists($filePath)) {
                 FileSystem::delete($filePath);
             }
         }
     }
     $cache->clean([Cache::TAGS => 'listing/' . $listing->id]);
 }
예제 #28
0
파일: Factory.php 프로젝트: netis-cms/netis
 /**
  * Factory for settings db host.
  * @param  class Translator
  * @param  callable
  * @return Form
  */
 public function databaseHostFactory($translator, callable $onSuccess)
 {
     $form = $this->forms->create($translator);
     $form->addText('host', 'install.db.host')->setRequired('install.form.empty');
     $form->addText('user', 'install.db.user')->setRequired('install.form.empty');
     $form->addText('password', 'install.db.pass');
     $form->addText('database', 'install.db.name')->setRequired('install.form.empty');
     $form->addText('prefix', 'install.db.prefix')->setAttribute('placeholder', 'ns_');
     // Database drivers.
     $drivers = ['mysql' => 'MySQL', 'mysqli' => 'MySQLi'];
     $form->addSelect('driver', 'install.db.driver', $drivers)->setRequired();
     $form->addSubmit('send', 'install.db.send');
     $form->onSuccess[] = function (Form $form, $values) use($onSuccess) {
         try {
             // Testing database connection.
             if (\dibi::connect($values)) {
                 // Parameters for generate config neon file.
                 $arr = ['extensions' => ['dibi' => 'Dibi\\Bridges\\Nette\\DibiExtension22'], 'dibi' => ['host' => $values->host, 'username' => $values->user, 'password' => $values->password, 'database' => $values->database, 'driver' => $values->driver, 'lazy' => TRUE, 'substitutes' => ['prefix' => $values->prefix]]];
                 // Generate and save the configuration file
                 $this->loader->save($arr, $this->dirs->getAppDir() . '/modules/app.db.neon');
                 // Removing the old cache for updating the configuration file.
                 FileSystem::delete($this->dirs->getTempDir() . '/cache/Nette.Configurator');
                 // Save the installation step into the cache.
                 $this->steps->setToCache(Steps::Step1, rand(1, 9));
                 // Save db prefix.
                 if ($values->prefix) {
                     $this->sessions->getSessionSection()->prefix = $values->prefix;
                 }
             }
         } catch (\Dibi\Exception $e) {
             // Server database type error.
             if ($e->getCode() == 0) {
                 $form->addError('install.db.driver.catch');
                 // Host server not found.
             } elseif ($e->getCode() == 2002) {
                 $form->addError('install.db.host.catch');
                 // The user or password was not verified.
             } elseif ($e->getCode() == 1045) {
                 $form->addError('install.db.auth.catch');
                 // The database name was not found
             } elseif ($e->getCode() == 1049) {
                 $form->addError('install.db.name.catch');
             }
             return;
         }
         $onSuccess();
     };
     return $form;
 }
예제 #29
0
파일: Latte.php 프로젝트: accgit/single-web
 /**
  * Setting templating system.
  * @return Engine
  */
 private function createLatteEngine()
 {
     // Create directory.
     $temp = $this->temp . '/_Latte.TemplateCache';
     if (!is_dir($temp)) {
         FileSystem::createDir($temp);
     }
     $latte = new Engine();
     $latte->setTempDirectory($temp);
     // Macro for forms.
     $latte->onCompile[] = function ($latte) {
         FormMacros::install($latte->getCompiler());
     };
     return $latte;
 }
예제 #30
0
 /**
  * Copies the SlimerJS binary to the bin folder
  *
  * @param string $binDir
  * @throws \Canterville\RuntimeException
  */
 protected function copyToBinFolder($binDir)
 {
     FileSystem::createDir($binDir);
     $os = Helpers::getOS();
     if ($os === Helpers::OS_WINDOWS) {
         $source = $this->targetDir . '/slimerjs.bat';
         $target = $binDir . '/slimerjs.bat';
     } elseif (isset($os)) {
         $source = $this->targetDir . '/slimerjs';
         $target = $binDir . '/slimerjs';
     } else {
         throw new RuntimeException('Cannot copy binary file of SlimerJS. OS not detect.');
     }
     Cli::makeSymbolicLink($source, $target);
 }