예제 #1
0
 public function testUpdate()
 {
     $path = 'path.txt';
     $contents = 'contents';
     $this->prophecy->has($path)->willReturn(true);
     $this->prophecy->update($path, $contents, $this->config)->willReturn(compact('path', 'contents'));
     $this->assertTrue($this->filesystem->update($path, $contents));
 }
예제 #2
0
 /**
  * @param string $content
  * @param string $path
  * @return bool
  * @throws \InvalidArgumentException
  * @throws \League\Flysystem\FileNotFoundException
  */
 public function publish($content, $path = '')
 {
     if (empty($path)) {
         throw new \InvalidArgumentException('Path is mandatory!');
     }
     $config = new Config();
     try {
         return $this->storage->write($path, $content, $config);
     } catch (FileExistsException $e) {
         return $this->storage->update($path, $content, $config);
     }
 }
예제 #3
0
    public function run()
    {
        $log = new Stream('php://stdout');
        /** @var Config $config */
        $config = Di::getDefault()->getShared('config');
        $expireDate = new DateTime('now', new DateTimeZone('UTC'));
        $expireDate->modify('+1 month');
        $baseUrl = rtrim($config->get('site')->url, '/');
        $content = <<<EOL
User-agent: *
Allow: /
Sitemap: {$baseUrl}/sitemap.xml
EOL;
        $adapter = new Local(dirname(dirname(__FILE__)) . '/public');
        $filesystem = new Filesystem($adapter);
        if ($filesystem->has('robots.txt')) {
            $result = $filesystem->update('robots.txt', $content);
        } else {
            $result = $filesystem->write('robots.txt', $content);
        }
        if ($result) {
            $log->info('The robots.txt was successfully updated');
        } else {
            $log->error('Failed to update the robots.txt file');
        }
    }
예제 #4
0
 public function update($path, $contents, array $config = [])
 {
     if (parent::update($path, $contents, $config)) {
         return $this->getAdapter()->getModel();
     } else {
         return false;
     }
 }
예제 #5
0
 /**
  * @inheritdoc
  */
 public function update($path, $contents, array $config = [])
 {
     try {
         return $this->fileSystem->update($this->getInnerPath($path), $contents, $config);
     } catch (FileNotFoundException $e) {
         throw $this->exceptionWrapper($e, $path);
     }
 }
예제 #6
0
 public function run()
 {
     $log = new Stream('php://stdout');
     /** @var Config $config */
     $config = Di::getDefault()->getShared('config');
     $expireDate = new DateTime('now', new DateTimeZone('UTC'));
     $expireDate->modify('+1 day');
     $sitemap = new DOMDocument("1.0", "UTF-8");
     $sitemap->formatOutput = true;
     $urlset = $sitemap->createElement('urlset');
     $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     $urlset->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $baseUrl = $config->get('site')->url;
     $url = $sitemap->createElement('url');
     $url->appendChild($sitemap->createElement('loc', $baseUrl));
     $url->appendChild($sitemap->createElement('changefreq', 'daily'));
     $url->appendChild($sitemap->createElement('priority', '1.0'));
     $urlset->appendChild($url);
     $karmaSql = 'number_views + ' . '((IF(votes_up IS NOT NULL, votes_up, 0) - IF(votes_down IS NOT NULL, votes_down, 0)) * 4) + ' . 'number_replies';
     $parametersPosts = ['conditions' => 'deleted != 1', 'columns' => "id, slug, modified_at, {$karmaSql} AS karma", 'order' => 'karma DESC'];
     $posts = Posts::find($parametersPosts);
     $parametersKarma = ['column' => $karmaSql, 'conditions' => 'deleted != 1'];
     $karma = Posts::maximum($parametersKarma);
     $modifiedAt = new DateTime('now', new DateTimeZone('UTC'));
     foreach ($posts as $post) {
         $modifiedAt->setTimestamp($post->modified_at);
         $postKarma = $post->karma / ($karma + 100);
         $url = $sitemap->createElement('url');
         $href = trim($baseUrl, '/') . '/discussion/' . $post->id . '/' . $post->slug;
         $url->appendChild($sitemap->createElement('loc', $href));
         $valuePriority = $postKarma > 0.7 ? sprintf("%0.1f", $postKarma) : sprintf("%0.1f", $postKarma + 0.25);
         $url->appendChild($sitemap->createElement('priority', $valuePriority));
         $url->appendChild($sitemap->createElement('lastmod', $modifiedAt->format('Y-m-d\\TH:i:s\\Z')));
         $urlset->appendChild($url);
     }
     $sitemap->appendChild($urlset);
     $adapter = new Local(dirname(dirname(__FILE__)) . '/public');
     $filesystem = new Filesystem($adapter);
     if ($filesystem->has('sitemap.xml')) {
         $result = $filesystem->update('sitemap.xml', $sitemap->saveXML() . PHP_EOL);
     } else {
         $result = $filesystem->write('sitemap.xml', $sitemap->saveXML() . PHP_EOL);
     }
     if ($result) {
         $log->info('The sitemap.xml was successfully updated');
     } else {
         $log->error('Failed to update the sitemap.xml file');
     }
 }
예제 #7
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $dir = $input->getOption("dir");
     $dir = realpath(getcwd() . "/" . ($dir ?: ""));
     if (!is_dir($dir) || !is_writeable($dir)) {
         $output->writeln("<error>Given directory does not exists or is not writeable</error>");
         return;
     }
     $fs = new Filesystem(new Adapter($dir));
     $files = $fs->listContents("", true);
     $updates = [];
     $errors = 0;
     foreach ($files as $file) {
         if ($file['type'] === 'dir') {
             continue;
         }
         $content = $fs->read($file['path']);
         $content = preg_replace_callback(static::SEMVER_REGEX, function ($matches) use(&$updates, &$errors, $input) {
             list($prefix, $ver) = array_slice($matches, 1);
             try {
                 $semver = new version($ver);
             } catch (\Exception $e) {
                 $errors++;
                 return $prefix . $ver;
             }
             if ($input->getOption("major")) {
                 $semver->inc("major");
             } elseif ($input->getOption("minor")) {
                 $semver->inc("minor");
             } elseif ($input->getOption("patch")) {
                 $semver->inc("patch");
             } else {
                 $semver->inc("patch");
             }
             if (!isset($updates[$ver])) {
                 $updates[$ver] = ["count" => 0, "ver" => $semver->getVersion()];
             }
             $updates[$ver]['count']++;
             return $prefix . $semver->getVersion();
         }, $content);
         $fs->update($file['path'], $content);
     }
     foreach ($updates as $update => $count) {
         $output->writeln("<info>{$count['count']} files have been updated from {$update} to {$count['ver']}</info>");
     }
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function touch($key, $expire)
 {
     if (!$this->lock($key)) {
         return false;
     }
     $value = $this->get($key);
     if ($value === false) {
         $this->unlock($key);
         return false;
     }
     $path = $this->path($key);
     $data = $this->wrap($value, $expire);
     try {
         $success = $this->filesystem->update($path, $data);
         return $success && $this->unlock($key);
     } catch (FileNotFoundException $e) {
         $this->unlock($key);
         return false;
     }
 }
예제 #9
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $version = $input->getArgument("version");
     try {
         $semver = new version($version);
     } catch (\Exception $e) {
         $output->writeln("<error>Given version is not valid. Please provide a semver version</error>");
         return;
     }
     $version = $semver->getVersion();
     $dir = $input->getOption("dir");
     $dir = realpath(getcwd() . "/" . ($dir ?: ""));
     if (!is_dir($dir) || is_writeable($dir)) {
         $output->writeln("Given directory does not exists or is not writeable");
         return;
     }
     $fs = new Filesystem(new Adapter($dir));
     $files = $fs->listContents("", true);
     $updates = [];
     foreach ($files as $file) {
         if ($file['type'] === 'dir') {
             continue;
         }
         $content = $fs->read($file['path']);
         $content = preg_replace_callback(static::SEMVER_REGEX, function ($matches) use($version, &$updates) {
             list($prefix, $ver) = array_slice($matches, 1);
             if (!isset($updates[$ver])) {
                 $updates[$ver] = 0;
             }
             $updates[$ver]++;
             return $prefix . $version;
         }, $content);
         $fs->update($file['path'], $content);
     }
     foreach ($updates as $update => $count) {
         $output->writeln("<info>{$count} files have been updated from {$update} to {$version}</info>");
     }
 }
예제 #10
0
 /**
  * {@inheritDoc}
  */
 public function update($path, $contents, array $config = [])
 {
     parent::update($path, $contents, $config);
     return $this->get($path);
 }
예제 #11
0
 /**
  * Update an existing file.
  *
  * @param string $path     The path of the existing file.
  * @param string $contents The file contents.
  * @param array  $config   An optional configuration array.
  *
  * @throws FileNotFoundException
  *
  * @return bool True on success, false on failure.
  */
 public function update($path, $contents, array $config = [])
 {
     $result = parent::update($path, $contents, $config);
     if ($result && ($resource = $this->get($path))) {
         return $this->dispatch(new SyncFile($resource));
     }
     return $result;
 }
예제 #12
0
            }
            krsort($files);
            $errorlog = $sqldir . array_shift($files)[0];
        }
        break;
    default:
        $file .= 'access_log';
        break;
}
// Windows is silly...
if (PHP_OS !== 'Darwin') {
    $errorlog = str_replace('_log', '.log', $file);
}
if (isset($_GET['action']) && $_GET['action'] == 'delete') {
    if ($filesystem->has($errorlog)) {
        $filesystem->update($errorlog, '');
    }
}
if ($filesystem->has($errorlog)) {
    $data = $filesystem->read($errorlog);
} else {
    $data = '';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://raw.githubusercontent.com/Section214/DS3-Log-Viewer/master/log-viewer.php');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$buffer = curl_exec($ch);
curl_close($ch);
if ($buffer) {
 /**
  * 1.txt
  * 2.txt.
  */
 public function testUpdate()
 {
     $this->assertTrue($this->filesystem->update('1.txt', '456'));
 }
예제 #14
0
 /**
  * @inheritdoc
  */
 public function update($path, $contents, array $config = [])
 {
     try {
         return parent::update($path, $contents, $config);
     } catch (\Exception $e) {
         $this->errors[] = StringHelper::replace(FileException::FILE_EXISTS, ['path' => $path]);
     }
     return false;
 }