protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln("<error>Be carreful, you might removes files you don't want to. You should backup your files beforehand to be sure everything still works as intended.</error>");
     $force = $input->getOption('force');
     $container = $this->getContainer();
     $fs = new FileSystem();
     $helper = $this->getHelper('question');
     //Parse the file directory and fetch the other directories
     //We should find Workspaces and Users. Workspaces being formatted like "WORKSPACE_[ID]
     $fileDir = $container->getParameter('claroline.param.files_directory');
     $iterator = new \DirectoryIterator($fileDir);
     foreach ($iterator as $pathinfo) {
         if ($pathinfo->isDir()) {
             $name = $pathinfo->getBasename();
             //look for workspaces
             if (strpos('_' . $name, 'WORKSPACE')) {
                 $parts = explode('_', $name);
                 $id = $parts[1];
                 $workspace = $container->get('claroline.manager.workspace_manager')->getWorkspaceById($id);
                 if (!$workspace) {
                     $continue = false;
                     if (!$force) {
                         $question = new ConfirmationQuestion('Do you really want to remove the directory ' . $pathinfo->getPathname() . ' [y/n] y ', true);
                         $continue = $helper->ask($input, $output, $question);
                     }
                     if ($continue || $force) {
                         $fs->remove($pathinfo->getPathname());
                     }
                 }
             }
         }
     }
 }
 public function connect(Application $app)
 {
     // creates a new controller based on the default route
     $controllers = $app['controllers_factory'];
     $names = [];
     foreach ($this->faculty->professors as $professor) {
         $names[] = $professor->name;
     }
     $fs = new FileSystem();
     $fs->remove($this->faculty->baseCacheDestination);
     $names = '(' . implode('|', $names) . ')';
     $faculty = $this->faculty;
     $controllers->get('/{processor}/{path}', function (Application $app, $processor, $path) use($faculty) {
         $exten = [];
         preg_match($faculty->extenstions, $path, $exten);
         $exten = ltrim($exten[0], '.');
         if (empty($exten)) {
             return $app->abort(404);
         }
         $faculty->process($processor, $path);
         $imagePath = $faculty->getLastProcessed()[0];
         return $app->sendFile($imagePath, 200, array('Content-Type' => 'image/' . $exten));
     })->assert('path', $this->faculty->extenstions);
     return $controllers;
 }
Exemplo n.º 3
0
 /**
  * Serve a file by forcing the download
  *
  * @Route("/download-task/{id}", name="download_file_task", requirements={"filename": ".+"})
  */
 public function downloadFileTaskAction($id)
 {
     /**
      * $basePath can be either exposed (typically inside web/)
      * or "internal"
      */
     $repository = $this->getDoctrine()->getRepository('TrackersBundle:Project_Task_Attachments');
     $files = $repository->find($id);
     if (empty($files)) {
         throw $this->createNotFoundException();
     }
     $filename = $files->getFileurl();
     $basePath = $this->get('kernel')->getRootDir() . '/../web/upload';
     $filePath = $basePath . '/' . $filename;
     $name_array = explode('/', $filename);
     $filename = $name_array[sizeof($name_array) - 1];
     // check if file exists
     $fs = new FileSystem();
     if (!$fs->exists($filePath)) {
         throw $this->createNotFoundException();
     }
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename=' . basename($filePath));
     header('Expires: 0');
     header('Cache-Control: must-revalidate');
     header('Pragma: public');
     header('Content-Length: ' . filesize($filePath));
     readfile($filePath);
     exit;
 }
Exemplo n.º 4
0
 /**
  * Get a File from a hash
  * @param  [string] $relativePath
  * @return File
  */
 public function getFile($relativePath)
 {
     if ($this->fileSystem->exists($this->getPath($relativePath))) {
         return new File($this->getPath($relativePath));
     }
     return false;
 }
Exemplo n.º 5
0
 public function extractTo($extractPath, $files = null)
 {
     $fs = new FileSystem();
     $ds = DIRECTORY_SEPARATOR;
     for ($i = 0; $i < $this->numFiles; $i++) {
         $oldName = parent::getNameIndex($i);
         $newName = mb_convert_encoding($this->getNameIndex($i), 'ISO-8859-1', 'CP850,UTF-8');
         //we cheat a little because we can't tell wich name the extracted part should have
         //so we put it a directory wich share it's name
         $tmpDir = $extractPath . $ds . '__claro_zip_hack_' . $oldName;
         parent::extractTo($tmpDir, parent::getNameIndex($i));
         //now we move the content of the directory and we put the good name on it.
         foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tmpDir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
             if ($item->isFile()) {
                 $fs->mkdir(dirname($extractPath . $ds . $oldName));
                 $fs->rename($item->getPathname(), $extractPath . $ds . $oldName);
             }
         }
     }
     //we remove our 'trash here'
     $iterator = new \DirectoryIterator($extractPath);
     foreach ($iterator as $item) {
         if (strpos($item->getFilename(), '_claro_zip_hack')) {
             $fs->rmdir($item->getRealPath(), true);
         }
     }
 }
Exemplo n.º 6
0
 private function checkRepositoryExists($path)
 {
     $fs = new FileSystem();
     if (!$fs->exists($path)) {
         throw new PayrollRepositoryDoesNotExist(sprintf('Path %s does not exist.', $path));
     }
 }
 public function testCleanUp()
 {
     $fs = new FileSystem();
     $fs->dumpFile($this->tmpDir . '/dummy-file', 'Dummy content.');
     $dw = new FilesystemDataWriter(new Filesystem(), $this->tmpDir);
     $dw->setUp();
     $this->assertFileNotExists($this->tmpDir . '/dummy-file');
 }
Exemplo n.º 8
0
 /**
  * @param string $key
  * @param string $val
  */
 public function remove($key, $val)
 {
     $key = $this->fs->relativePath($key);
     $val = $this->fs->relativePath($val);
     if (array_key_exists($key, $this->cache)) {
         unset($this->cache[$key][$val]);
     }
 }
Exemplo n.º 9
0
 /**
  * Upload the call script to a remote file store
  *
  * @param string $path
  * @param OutputInterface $output
  *
  * @return mixed
  */
 protected function uploadCallScript($path, OutputInterface $output)
 {
     if (!($script = $this->getScript($path))) {
         $output->writeln("<error>{$path} is not a valid file</error>");
         return false;
     }
     $this->uploadName = pathinfo($path, PATHINFO_FILENAME) . '.' . pathinfo($path, PATHINFO_EXTENSION);
     return $this->fileSystem->put($this->uploadName, $script, ['visibility' => 'public']);
 }
Exemplo n.º 10
0
 /**
  * Write a file
  *
  * @param string $path The directory to put the file in (in the current destination)
  * @param string $content The file content
  * @param string $filename The file name
  * @param string $extension The file extension
  */
 public function write($path, $content, $extension = 'html', $filename = 'index')
 {
     $directory = sprintf('%s/%s', $this->destination, trim($path, '/'));
     $file = sprintf('%s.%s', $filename, $extension);
     if (!$this->files->exists($directory)) {
         $this->files->mkdir($directory);
     }
     $this->files->dumpFile(sprintf('%s/%s', $directory, $file), $content);
 }
Exemplo n.º 11
0
 public function cleanupClientSpec()
 {
     $client = $this->getClient();
     $command = 'p4 client -d $client';
     $this->executeCommand($command);
     $clientSpec = $this->getP4ClientSpec();
     $fileSystem = new FileSystem($this->process);
     $fileSystem->remove($clientSpec);
 }
Exemplo n.º 12
0
function main()
{
    if (false === auth()) {
        error("Not logged in", 403);
    }
    $fs = new FileSystem();
    $file = $fs->getOwnFile();
    $fs->delete($file);
}
 /**
  * @DI\Observe("kernel.terminate")
  */
 public function onKernelTerminate(PostResponseEvent $event)
 {
     if (count($this->elementsToRemove) > 0) {
         $fs = new FileSystem();
         foreach ($this->elementsToRemove as $element) {
             $fs->remove($element);
         }
     }
 }
Exemplo n.º 14
0
 /**
  * Loads app config from environment source code into $this->config
  */
 private function loadConfig()
 {
     // Look for .director.yml
     $fs = new FileSystem();
     if ($fs->exists($this->getSourcePath() . '/.director.yml')) {
         $this->config = Yaml::parse(file_get_contents($this->getSourcePath() . '/.director.yml'));
     } else {
         $this->config = NULL;
     }
 }
 public static function savePsr4s($vendorDir, $localPsr4Config, $io)
 {
     $filesystem = new FileSystem();
     $psr4File = $filesystem->normalizePath(realpath($vendorDir . self::PSR4_FILE));
     if ($localPsr4Config && $psr4File) {
         $io->write('generating local autoload_psr4.php ....');
         self::appendBeforeLastline($localPsr4Config, $psr4File);
         $io->write('local autoload_psr4 generated.');
     }
 }
Exemplo n.º 16
0
 public function removeModuleFromDisk($name)
 {
     $fs = new FileSystem();
     try {
         $fs->remove(_PS_MODULE_DIR_ . '/' . $name);
         return true;
     } catch (IOException $e) {
         return false;
     }
 }
Exemplo n.º 17
0
 /**
  * Used to get tags within given template file
  * 
  * It reads a template file and extracts all the tags in the template file
  * 
  * @since 1.0.1 
  * @param string $template_path absolute path to the template html file
  * 
  * @return array $template_information an array with 2 elements.
  * first one is the template contents string.
  * the second one is the template tag replacement string
  */
 function ExtractTemplateFileTags($template_path)
 {
     /** The filesystem object */
     $filesystem_obj = new FileSystem(array());
     $template_contents = $filesystem_obj->ReadLocalFile($template_path);
     /** All template tags of the form {} are extracted from the template file */
     preg_match_all("/\\{(.+)\\}/iU", $template_contents, $matches);
     $template_tag_list = $matches[1];
     $template_information = array($template_contents, $template_tag_list);
     return $template_information;
 }
Exemplo n.º 18
0
 /**
  * Compute a hash to identify the list of repos/checkouts
  * within a given base dir.
  *
  * @param string $basedir
  * @return string
  */
 public function hash($basedir)
 {
     $gitRepos = $this->scan($basedir);
     $buf = '';
     foreach ($gitRepos as $gitRepo) {
         $path = rtrim($this->fs->makePathRelative($gitRepo->getPath(), $basedir), '/');
         /** @var $gitRepo GitRepo */
         $buf .= ';;' . $path;
         $buf .= ';;' . $gitRepo->getCommit();
     }
     return md5($buf);
 }
Exemplo n.º 19
0
 public function deleteExistingFile($fileIdWithoutExtension, $fileFullPath)
 {
     $fs = new FileSystem();
     if ($fs->exists($fileFullPath . $fileIdWithoutExtension . '.docx')) {
         unlink($fileFullPath . $fileIdWithoutExtension . '.docx');
     } elseif ($fs->exists($fileFullPath . $fileIdWithoutExtension . '.doc')) {
         unlink($fileFullPath . $fileIdWithoutExtension . '.doc');
     } elseif ($fs->exists($fileFullPath . $fileIdWithoutExtension . '.pdf')) {
         unlink($fileFullPath . $fileIdWithoutExtension . '.pdf');
     }
     return;
 }
Exemplo n.º 20
0
 private function getControllers($controllerDirectory)
 {
     $result = array();
     /**
      * @var $file SplFileInfo
      */
     foreach ($this->fileSystem->getFilesRecursively($controllerDirectory) as $file) {
         if (preg_match('/([a-z0-9]+Controller).class.php/i', $file->getFilename(), $matches)) {
             $result[] = $matches[1];
         }
     }
     return $result;
 }
Exemplo n.º 21
0
 public function testNewSiteExistsEmptyDir()
 {
     $fs = new FileSystem();
     $fs->mkdir($this->tmpDir);
     $this->assertFileExists($this->tmpDir);
     $operation = new NewSite($this->templatePath);
     $operation->newSite($this->tmpDir, 'blank');
     $this->assertFileExists($this->tmpDir . '/config.yml');
     $this->assertFileExists($this->tmpDir . '/composer.json');
     $this->assertFileExists($this->tmpDir . '/index.html');
     $this->assertFileExists($this->tmpDir . '/_posts');
     $this->assertFileExists($this->tmpDir . '/_layouts');
 }
Exemplo n.º 22
0
 public function testNewSiteExistsEmptyDir()
 {
     $fs = new FileSystem();
     $fs->mkdir($this->tmpDir);
     $this->assertFileExists($this->tmpDir);
     $app = new Application();
     $app->add(new NewSiteCommand());
     $command = $app->find('new:site');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'path' => $this->tmpDir]);
     $output = $commandTester->getDisplay();
     $this->assertRegExp('/New site created/', $output);
 }
Exemplo n.º 23
0
 /**
  * Writes the class to a file.
  */
 public function write()
 {
     try {
         $dir = $this->path->isDir() ? $this->path->getPathname() : $this->path->getPath();
         $path = $dir . '/' . $this->baseClass->getClassName() . $this->baseClass->getExtension();
         if (!file_exists($dir)) {
             $this->fileSystem->mkdir($dir, 0777, true);
         }
         //if (!file_exists($path)) {
         file_put_contents($path, $this->baseClass->generate());
         //}
     } catch (IOExceptionInterface $e) {
     }
 }
Exemplo n.º 24
0
 /**
  * Highlight a portion of code with pygmentize
  *
  * @param string $value
  * @param string $language
  *
  * @return string
  */
 public function highlight($value, $language)
 {
     $path = tempnam($this->tmp, 'pyg');
     if ($language === 'php' && substr($value, 0, 5) !== '<?php') {
         $value = '<?php ' . PHP_EOL . $value;
     }
     $this->files->dumpFile($path, $value);
     $value = $this->pygmentize($path, $language);
     unlink($path);
     if (preg_match('#^<div class="highlight"><pre>#', $value) && preg_match('#</pre></div>$#', $value)) {
         return substr($value, 28, strlen($value) - 40);
     }
     return $value;
 }
Exemplo n.º 25
0
 public static function getJson($code, $path = '/', $type = 'arr')
 {
     import('ORG.Net.FileSystem');
     $sys = new FileSystem();
     //main
     $basepath = RUNTIME_PATH . 'Data/Json/' . $path;
     $filename = '/' . $code . '_data.json';
     $json = $sys->getFile($basepath . $filename);
     if ($type == 'obj') {
         return json_decode($json);
     } elseif ($type == 'arr') {
         return json_decode($json, true);
     }
 }
Exemplo n.º 26
0
 public function write($path, $data, $mode)
 {
     import('ORG.Net.FileSystem');
     $paths = new FileSystem();
     $paths->root = ITEM;
     $paths->charset = C('CFG_CHARSET');
     //main
     if ($mode == 'conf') {
         if (!is_writeable(ROOT . '/Conf')) {
             return -1;
         }
         $fp = fopen($path, 'wb');
         flock($fp, 3);
         fwrite($fp, "<" . "?php\r\n");
         fwrite($fp, "return array(\r\n");
         //dump($data);
         foreach ($data as $fval) {
             $fval['vals'] = htmlspecialchars_decode($fval['vals']);
             if ($fval['types'] == 'int' || $fval['types'] == 'bool') {
                 if ($fval['vals'] == "") {
                     $fval['vals'] = 0;
                 }
                 fwrite($fp, "\t'" . $fval['keyword'] . "' => " . addslashes($fval['vals']) . ",\r\n");
             } elseif ($fval['types'] == 'select' || $fval['types'] == 'more') {
                 list($key, $val) = explode('>>', $fval['vals']);
                 if ($key == 'none') {
                     fwrite($fp, "\t'" . $fval['keyword'] . "' => '',\r\n");
                 } else {
                     fwrite($fp, "\t'" . $fval['keyword'] . "' => '" . addslashes($key) . "',\r\n");
                 }
             } else {
                 fwrite($fp, "\t'" . $fval['keyword'] . "' => '" . addslashes($fval['vals']) . "',\r\n");
             }
         }
         fwrite($fp, ");");
         fclose($fp);
         return 1;
     } elseif ($mode && $mode != 'conf') {
         if (!file_exists($path)) {
             $paths->putDir($path);
         }
         if (!is_writeable($path)) {
             return -1;
         }
         $put = $paths->putFile($path . '/' . $mode . '.json', $data);
         return $put;
     } else {
         $this->error('未知操作模式,请检查!');
     }
 }
 protected function setSystemCrontab(OutputInterface $output, $newContents)
 {
     $tempCronFileName = '/tmp/madrak_io_easy_cron_deployment.cron.' . time();
     $filesystem = new FileSystem();
     $filesystem->dumpFile($tempCronFileName, $newContents);
     $process = new Process('crontab ' . $tempCronFileName);
     try {
         $process->mustRun();
         return $process->getOutput();
     } catch (ProcessFailedException $e) {
         $this->outputFormattedBlock($output, ['Error!', 'There was an error while attempting to overwrite the existing crontab list.', $e->getMessage()], 'error');
         exit;
     }
 }
Exemplo n.º 28
0
 public function testGetFile()
 {
     $fs = new SymfonyFileSystem();
     $someJunk = 'whatever dude';
     $hash = md5($someJunk);
     $testFilePath = $this->uploadDirectory . '/' . $hash;
     file_put_contents($testFilePath, $someJunk);
     $file = m::mock('Symfony\\Component\\HttpFoundation\\File\\File')->shouldReceive('getPathname')->andReturn($testFilePath)->getMock();
     $this->mockFileSystem->shouldReceive('exists')->with($testFilePath)->andReturn(true);
     $this->mockFileSystem->shouldReceive('move');
     $newHash = $this->tempFileSystem->storeFile($file, false);
     $newFile = $this->tempFileSystem->getFile($newHash);
     $this->assertSame($hash, $newHash);
     $this->assertSame(file_get_contents($newFile->getPathname()), $someJunk);
 }
Exemplo n.º 29
0
 /**
  * Get unique but consistent name
  * @param  string  $name
  * @param  string  $type
  * @param  integer $index
  * @param  array   $content_range
  * @param  string  $extension
  * @return string
  */
 protected function getUniqueFilename($name, $type, $index, $content_range, $extension)
 {
     $name = $this->generateRandom() . "." . $extension;
     while ($this->filesystem->isDir($this->pathresolver->getUploadPath($name))) {
         $name = $this->generateRandom() . "." . $extension;
     }
     $uploaded_bytes = Util::fixIntegerOverflow(intval($content_range[1]));
     while ($this->filesystem->isFile($this->pathresolver->getUploadPath($name))) {
         if ($uploaded_bytes == $this->filesystem->getFilesize($this->pathresolver->getUploadPath($name))) {
             break;
         }
         $name = $this->generateRandom() . "." . $extension;
     }
     return $name;
 }
Exemplo n.º 30
0
 public function removeInstallationFiles()
 {
     chdir($this->dir_opencart);
     if (is_file($this->dir_opencart . DIRECTORY_SEPARATOR . "config-dist.php")) {
         unlink($this->dir_opencart . DIRECTORY_SEPARATOR . "config-dist.php");
     }
     if (is_file($this->dir_opencart . DIRECTORY_SEPARATOR . "admin" . DIRECTORY_SEPARATOR . "config-dist.php")) {
         unlink($this->dir_opencart . DIRECTORY_SEPARATOR . "admin" . DIRECTORY_SEPARATOR . "config-dist.php");
     }
     // remove install folder
     if (is_dir($this->dir_opencart . DIRECTORY_SEPARATOR . "install")) {
         $fsh = new FileSystem();
         $fsh->rmdir($this->dir_opencart . DIRECTORY_SEPARATOR . "install");
     }
 }