Exemplo n.º 1
7
 public function setup()
 {
     clearstatcache();
     $fs = new Adapter\Local(__DIR__ . '/');
     $fs->deleteDir('files');
     $fs->createDir('files');
 }
Exemplo n.º 2
1
 public function testCloseStream()
 {
     //ensure all basic stream stuff works
     $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
     $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt');
     $file = 'close://' . $tmpFile;
     $this->assertTrue(file_exists($file));
     file_put_contents($file, file_get_contents($sourceFile));
     $this->assertEquals(file_get_contents($sourceFile), file_get_contents($file));
     unlink($file);
     clearstatcache();
     $this->assertFalse(file_exists($file));
     //test callback
     $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt');
     $file = 'close://' . $tmpFile;
     $actual = false;
     $callback = function ($path) use(&$actual) {
         $actual = $path;
     };
     \OC\Files\Stream\Close::registerCallback($tmpFile, $callback);
     $fh = fopen($file, 'w');
     fwrite($fh, 'asd');
     fclose($fh);
     $this->assertSame($tmpFile, $actual);
 }
Exemplo n.º 3
0
 public function __construct()
 {
     $defaults = array('chuser' => false, 'uid' => 99, 'gid' => 99, 'maxTimes' => 0, 'maxMemory' => 0, 'limitMemory' => 0, 'log' => '/tmp/' . get_class($this) . '.log', 'pid' => '/tmp/' . get_class($this) . '.pid', 'help' => "Usage:\n\n{$_SERVER['_']} " . __FILE__ . " start|stop|restart|status|help\n\n");
     $this->_options += $defaults;
     ini_set('memory_limit', $this->_options['limitMemory']);
     clearstatcache();
 }
Exemplo n.º 4
0
 /**
  * Generate doctrine proxy classes for extended entities for the given entity manager
  *
  * @param EntityManager $em
  */
 protected function generateEntityManagerProxies(EntityManager $em)
 {
     $isAutoGenerated = $em->getConfiguration()->getAutoGenerateProxyClasses();
     if (!$isAutoGenerated) {
         $proxyDir = $em->getConfiguration()->getProxyDir();
         if (!empty($this->cacheDir) && $this->kernelCacheDir !== $this->cacheDir && strpos($proxyDir, $this->kernelCacheDir) === 0) {
             $proxyDir = $this->cacheDir . substr($proxyDir, strlen($this->kernelCacheDir));
         }
         $metadataFactory = $em->getMetadataFactory();
         $proxyFactory = $em->getProxyFactory();
         $extendConfigs = $this->extendConfigProvider->getConfigs(null, true);
         foreach ($extendConfigs as $extendConfig) {
             if (!$extendConfig->is('is_extend')) {
                 continue;
             }
             if ($extendConfig->in('state', [ExtendScope::STATE_NEW])) {
                 continue;
             }
             $entityClass = $extendConfig->getId()->getClassName();
             $proxyFileName = $proxyDir . DIRECTORY_SEPARATOR . '__CG__' . str_replace('\\', '', $entityClass) . '.php';
             $metadata = $metadataFactory->getMetadataFor($entityClass);
             $proxyFactory->generateProxyClasses([$metadata], $proxyDir);
             clearstatcache(true, $proxyFileName);
         }
     }
 }
 /**
  * Tests a simple composer install without core, but adding core later.
  */
 public function testComposerInstallAndUpdate()
 {
     $exampleScaffoldFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'index.php';
     $this->assertFileNotExists($exampleScaffoldFile, 'Scaffold file should not be exist.');
     $this->composer('install');
     $this->assertFileExists($this->tmpDir . DIRECTORY_SEPARATOR . 'core', 'Drupal core is installed.');
     $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be automatically installed.');
     $this->fs->remove($exampleScaffoldFile);
     $this->assertFileNotExists($exampleScaffoldFile, 'Scaffold file should not be exist.');
     $this->composer('drupal-scaffold');
     $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be installed by "drupal-scaffold" command.');
     foreach (['8.0.1', '8.1.x-dev'] as $version) {
         // We touch a scaffold file, so we can check the file was modified after
         // the scaffold update.
         touch($exampleScaffoldFile);
         $mtime_touched = filemtime($exampleScaffoldFile);
         // Requiring a newer version triggers "composer update"
         $this->composer('require --update-with-dependencies drupal/core:"' . $version . '"');
         clearstatcache();
         $mtime_after = filemtime($exampleScaffoldFile);
         $this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by composer update. (' . $version . ')');
     }
     // We touch a scaffold file, so we can check the file was modified after
     // the custom commandscaffold update.
     touch($exampleScaffoldFile);
     clearstatcache();
     $mtime_touched = filemtime($exampleScaffoldFile);
     $this->composer('drupal-scaffold');
     clearstatcache();
     $mtime_after = filemtime($exampleScaffoldFile);
     $this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by custom command.');
 }
Exemplo n.º 6
0
 public function initRunFolder()
 {
     clearstatcache();
     if (!File::exists($this->tmpRunFolder) && !is_dir($this->tmpRunFolder)) {
         $this->filesystem->mkdir($this->tmpRunFolder);
     }
 }
Exemplo n.º 7
0
function is_page($page, $clearcache = FALSE)
{
    if ($clearcache) {
        clearstatcache();
    }
    return file_exists(get_filename($page));
}
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function write($key, $content)
 {
     $dir = dirname($key);
     if (!is_dir($dir)) {
         if (false === @mkdir($dir, 0777, true)) {
             clearstatcache(false, $dir);
             if (!is_dir($dir)) {
                 throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
             }
         }
     } elseif (!is_writable($dir)) {
         throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
     }
     $tmpFile = tempnam($dir, basename($key));
     if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) {
         @chmod($key, 0666 & ~umask());
         if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
             // Compile cached file into bytecode cache
             if (function_exists('opcache_invalidate')) {
                 opcache_invalidate($key, true);
             } elseif (function_exists('apc_compile_file')) {
                 apc_compile_file($key);
             }
         }
         return;
     }
     throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key));
 }
Exemplo n.º 9
0
 public function testExecute()
 {
     $application = $this->getApplication();
     $application->add(new ListCommand());
     $command = $this->getApplication()->find('dev:module:create');
     $root = getcwd();
     // delete old module
     if (is_dir($root . '/N98Magerun_UnitTest')) {
         $filesystem = new Filesystem();
         $filesystem->recursiveRemoveDirectory($root . '/N98Magerun_UnitTest');
         clearstatcache();
     }
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), '--add-all' => true, '--add-setup' => true, '--add-readme' => true, '--add-composer' => true, '--modman' => true, '--description' => 'Unit Test Description', '--author-name' => 'Unit Test', '--author-email' => '*****@*****.**', 'vendorNamespace' => 'N98Magerun', 'moduleName' => 'UnitTest'));
     $this->assertFileExists($root . '/N98Magerun_UnitTest/composer.json');
     $this->assertFileExists($root . '/N98Magerun_UnitTest/readme.md');
     $moduleBaseFolder = $root . '/N98Magerun_UnitTest/src/app/code/local/N98Magerun/UnitTest/';
     $this->assertFileExists($moduleBaseFolder . 'etc/config.xml');
     $this->assertFileExists($moduleBaseFolder . 'Block');
     $this->assertFileExists($moduleBaseFolder . 'Model');
     $this->assertFileExists($moduleBaseFolder . 'Helper');
     $this->assertFileExists($moduleBaseFolder . 'data/n98magerun_unittest_setup');
     $this->assertFileExists($moduleBaseFolder . 'sql/n98magerun_unittest_setup');
     // delete old module
     if (is_dir($root . '/N98Magerun_UnitTest')) {
         $filesystem = new Filesystem();
         $filesystem->recursiveRemoveDirectory($root . '/N98Magerun_UnitTest');
         clearstatcache();
     }
 }
Exemplo n.º 10
0
 function doRewrite()
 {
     clearstatcache();
     if (!($file = fopen($this->path, "r"))) {
         $this->error = true;
         return false;
     }
     $content = fread($file, filesize($this->path));
     fclose($file);
     foreach ($this->rewrite as $key => $val) {
         $val = str_replace('$', '\\$', $val);
         if (is_int($val) && preg_match("/(define\\()([\"'])(" . $key . ")\\2,\\s*([0-9]+)\\s*\\)/", $content)) {
             $content = preg_replace("/(define\\()([\"'])(" . $key . ")\\2,\\s*([0-9]+)\\s*\\)/", "define('" . $key . "', " . $val . ")", $content);
             $this->report .= _OKIMG . sprintf(_INSTALL_L121, "<b>{$key}</b>", $val) . "<br />\n";
         } elseif (preg_match("/(define\\()([\"'])(" . $key . ")\\2,\\s*([\"'])(.*?)\\4\\s*\\)/", $content)) {
             $content = preg_replace("/(define\\()([\"'])(" . $key . ")\\2,\\s*([\"'])(.*?)\\4\\s*\\)/", "define('" . $key . "', '" . $val . "')", $content);
             $this->report .= _OKIMG . sprintf(_INSTALL_L121, "<b>{$key}</b>", $val) . "<br />\n";
         } else {
             $this->error = true;
             $this->report .= _NGIMG . sprintf(_INSTALL_L122, "<b>{$key}</b>", $val) . "<br />\n";
         }
     }
     if (!($file = fopen($this->path, "w"))) {
         $this->error = true;
         return false;
     }
     if (fwrite($file, $content) == -1) {
         fclose($file);
         $this->error = true;
         return false;
     }
     fclose($file);
     return true;
 }
Exemplo n.º 11
0
 /**
  * Handle a single request
  *
  * @param   string method request method
  * @param   string query query string
  * @param   [:string] headers request headers
  * @param   string data post data
  * @param   peer.Socket socket
  * @return  int
  */
 public function handleRequest($method, $query, array $headers, $data, Socket $socket)
 {
     $url = parse_url($query);
     $f = new File($this->docroot, strtr(preg_replace('#\\.\\./?#', '/', urldecode($url['path'])), '/', DIRECTORY_SEPARATOR));
     if (!is_file($f->getURI())) {
         return call_user_func($this->notFound, $this, $socket, $url['path']);
     }
     // Implement If-Modified-Since/304 Not modified
     $lastModified = $f->lastModified();
     if ($mod = $this->header($headers, 'If-Modified-Since')) {
         $d = strtotime($mod);
         if ($lastModified <= $d) {
             $this->sendHeader($socket, 304, 'Not modified', []);
             return 304;
         }
     }
     clearstatcache();
     try {
         $f->open(File::READ);
     } catch (IOException $e) {
         $this->sendErrorMessage($socket, 500, 'Internal server error', $e->getMessage());
         $f->close();
         return 500;
     }
     // Send OK header and data in 8192 byte chunks
     $this->sendHeader($socket, 200, 'OK', ['Last-Modified: ' . gmdate('D, d M Y H:i:s T', $lastModified), 'Content-Type: ' . MimeType::getByFileName($f->getFilename()), 'Content-Length: ' . $f->size()]);
     while (!$f->eof()) {
         $socket->write($f->read(8192));
     }
     $f->close();
     return 200;
 }
 /**
  * {@inheritDoc}
  */
 public function boot()
 {
     // Register an autoloader for proxies to avoid issues when unserializing them
     // when the ORM is used.
     if ($this->container->hasParameter('doctrine.orm.proxy_namespace')) {
         $namespace = $this->container->getParameter('doctrine.orm.proxy_namespace');
         $dir = $this->container->getParameter('doctrine.orm.proxy_dir');
         $proxyGenerator = null;
         if ($this->container->getParameter('doctrine.orm.auto_generate_proxy_classes')) {
             // See https://github.com/symfony/symfony/pull/3419 for usage of references
             $container =& $this->container;
             $proxyGenerator = function ($proxyDir, $proxyNamespace, $class) use(&$container) {
                 $originalClassName = ClassUtils::getRealClass($class);
                 /** @var $registry Registry */
                 $registry = $container->get('doctrine');
                 // Tries to auto-generate the proxy file
                 /** @var $em \Doctrine\ORM\EntityManager */
                 foreach ($registry->getManagers() as $em) {
                     if (!$em->getConfiguration()->getAutoGenerateProxyClasses()) {
                         continue;
                     }
                     $metadataFactory = $em->getMetadataFactory();
                     if ($metadataFactory->isTransient($originalClassName)) {
                         continue;
                     }
                     $classMetadata = $metadataFactory->getMetadataFor($originalClassName);
                     $em->getProxyFactory()->generateProxyClasses(array($classMetadata));
                     clearstatcache(true, Autoloader::resolveFile($proxyDir, $proxyNamespace, $class));
                     break;
                 }
             };
         }
         $this->autoloader = Autoloader::register($dir, $namespace, $proxyGenerator);
     }
 }
Exemplo n.º 13
0
 function isValid($id, $group = 'default', $doNotTestCacheValidity = false)
 {
     $this->_id = $id;
     $this->_group = $group;
     if ($this->_caching) {
         $this->_setRefreshTime();
         $this->_setFileName($id, $group);
         clearstatcache();
         if ($this->_memoryCaching) {
             if (isset($this->_memoryCachingArray[$this->_file])) {
                 return true;
             }
             if ($this->_onlyMemoryCaching) {
                 return false;
             }
         }
         if ($doNotTestCacheValidity || is_null($this->_refreshTime)) {
             if (file_exists($this->_file)) {
                 return true;
             }
         } else {
             if (file_exists($this->_file) && @filemtime($this->_file) > $this->_refreshTime) {
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 14
0
function cron_auto_del_temp_download()
{
    $dir = NV_ROOTDIR . '/' . NV_TEMP_DIR;
    $result = true;
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if (preg_match('/^(' . nv_preg_quote(NV_TEMPNAM_PREFIX) . ')[a-zA-Z0-9\\_\\.]+$/', $file)) {
                if (filemtime($dir . '/' . $file) + 600 < NV_CURRENTTIME) {
                    if (is_file($dir . '/' . $file)) {
                        if (!@unlink($dir . '/' . $file)) {
                            $result = false;
                        }
                    } else {
                        $rt = nv_deletefile($dir . '/' . $file, true);
                        if ($rt[0] == 0) {
                            $result = false;
                        }
                    }
                }
            }
        }
        closedir($dh);
        clearstatcache();
    }
    return $result;
}
Exemplo n.º 15
0
function debug($data)
{
    global $timezone;
    if (function_exists("date_default_timezone_set")) {
        // php 5.1.x
        @date_default_timezone_set($timezone);
    }
    $debug_file = "./tfu.log";
    $debug_string = date("m.d.Y G:i:s") . " - " . $data . "\n\n";
    if (file_exists($debug_file)) {
        if (filesize($debug_file) > 1000000) {
            // debug file max = 1MB !
            $debug_file_local = fopen($debug_file, 'w');
        } else {
            $debug_file_local = fopen($debug_file, 'a');
        }
        fputs($debug_file_local, $debug_string);
        fclose($debug_file_local);
    } else {
        if (is_writeable(dirname(__FILE__))) {
            $debug_file_local = fopen($debug_file, 'w');
            fputs($debug_file_local, $debug_string);
            fclose($debug_file_local);
            clearstatcache();
        } else {
            error_log($debug_string, 0);
        }
    }
}
Exemplo n.º 16
0
 public function testCloseStream()
 {
     //ensure all basic stream stuff works
     $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
     $tmpFile = OC_Helper::TmpFile('.txt');
     $file = 'close://' . $tmpFile;
     $this->assertTrue(file_exists($file));
     file_put_contents($file, file_get_contents($sourceFile));
     $this->assertEquals(file_get_contents($sourceFile), file_get_contents($file));
     unlink($file);
     clearstatcache();
     $this->assertFalse(file_exists($file));
     //test callback
     $tmpFile = OC_Helper::TmpFile('.txt');
     $file = 'close://' . $tmpFile;
     \OC\Files\Stream\Close::registerCallback($tmpFile, array('Test_StreamWrappers', 'closeCallBack'));
     $fh = fopen($file, 'w');
     fwrite($fh, 'asd');
     try {
         fclose($fh);
         $this->fail('Expected exception');
     } catch (Exception $e) {
         $path = $e->getMessage();
         $this->assertEquals($path, $tmpFile);
     }
 }
Exemplo n.º 17
0
 private function renameFile()
 {
     clearstatcache();
     if (file_exists($this->filePath)) {
         $size = filesize($this->filePath);
         if ($size >= $this->limitSize) {
             $dir = opendir($this->path);
             $ar = array();
             while ($file = readdir($dir)) {
                 if ($this->isFileLog($file)) {
                     $number = $this->getNumberFile($file);
                     array_push($ar, $number);
                 }
             }
             sort($ar);
             $n = count($ar);
             for ($i = $n - 1; $i >= 0; $i--) {
                 $oldName = $this->path . $this->fileName . $this->fileSeparatorVersion . $ar[$i] . $this->fileExtension;
                 $newName = $this->path . $this->fileName . $this->fileSeparatorVersion . ($i + 2) . $this->fileExtension;
                 if ($i + 1 >= $this->limitFile) {
                     unlink($oldName);
                 } else {
                     rename($oldName, $newName);
                 }
             }
             rename($this->filePath, $this->path . $this->fileName . $this->fileSeparatorVersion . 1 . $this->fileExtension);
         }
     }
 }
Exemplo n.º 18
0
 /**
  * @medium
  */
 function testWatcher()
 {
     $storage = $this->getTestStorage();
     $cache = $storage->getCache();
     $updater = $storage->getWatcher();
     //set the mtime to the past so it can detect an mtime change
     $cache->put('', array('storage_mtime' => 10));
     $this->assertTrue($cache->inCache('folder/bar.txt'));
     $this->assertTrue($cache->inCache('folder/bar2.txt'));
     $this->assertFalse($cache->inCache('bar.test'));
     $storage->file_put_contents('bar.test', 'foo');
     $updater->checkUpdate('');
     $this->assertTrue($cache->inCache('bar.test'));
     $cachedData = $cache->get('bar.test');
     $this->assertEquals(3, $cachedData['size']);
     $cache->put('bar.test', array('storage_mtime' => 10));
     $storage->file_put_contents('bar.test', 'test data');
     // make sure that PHP can read the new size correctly
     clearstatcache();
     $updater->checkUpdate('bar.test');
     $cachedData = $cache->get('bar.test');
     $this->assertEquals(9, $cachedData['size']);
     $cache->put('folder', array('storage_mtime' => 10));
     $storage->unlink('folder/bar2.txt');
     $updater->checkUpdate('folder');
     $this->assertTrue($cache->inCache('folder/bar.txt'));
     $this->assertFalse($cache->inCache('folder/bar2.txt'));
 }
Exemplo n.º 19
0
 /**
  * Extract a frame from a movie file.  Valid movie_options are start_time (in seconds),
  * input_args (extra ffmpeg input args) and output_args (extra ffmpeg output args).  Extra args
  * are added at the end of the list, so they can override any prior args.
  *
  * @param string     $input_file
  * @param string     $output_file
  * @param array      $movie_options (optional)
  */
 static function extract_frame($input_file, $output_file, $movie_options = null)
 {
     $ffmpeg = movie::find_ffmpeg();
     if (empty($ffmpeg)) {
         throw new Exception("@todo MISSING_FFMPEG");
     }
     list($width, $height, $mime_type, $extension, $duration) = movie::get_file_metadata($input_file);
     if (isset($movie_options["start_time"]) && is_numeric($movie_options["start_time"])) {
         $start_time = max(0, $movie_options["start_time"]);
         // ensure it's non-negative
     } else {
         $start_time = module::get_var("gallery", "movie_extract_frame_time", 3);
         // use default
     }
     // extract frame at start_time, unless movie is too short
     $start_time_arg = $duration >= $start_time + 0.1 ? "-ss " . movie::seconds_to_hhmmssdd($start_time) : "";
     $input_args = isset($movie_options["input_args"]) ? $movie_options["input_args"] : "";
     $output_args = isset($movie_options["output_args"]) ? $movie_options["output_args"] : "";
     $cmd = escapeshellcmd($ffmpeg) . " {$input_args} -i " . escapeshellarg($input_file) . " -an {$start_time_arg} -an -r 1 -vframes 1" . " -s {$width}x{$height}" . " -y -f mjpeg {$output_args} " . escapeshellarg($output_file) . " 2>&1";
     exec($cmd, $exec_output, $exec_return);
     clearstatcache();
     // use $filename parameter when PHP_version is 5.3+
     if (filesize($output_file) == 0 || $exec_return) {
         // Maybe the movie needs the "-threads 1" argument added
         // (see http://sourceforge.net/apps/trac/gallery/ticket/1924)
         $cmd = escapeshellcmd($ffmpeg) . " -threads 1 {$input_args} -i " . escapeshellarg($input_file) . " -an {$start_time_arg} -an -r 1 -vframes 1" . " -s {$width}x{$height}" . " -y -f mjpeg {$output_args} " . escapeshellarg($output_file) . " 2>&1";
         exec($cmd, $exec_output, $exec_return);
         clearstatcache();
         if (filesize($output_file) == 0 || $exec_return) {
             throw new Exception("@todo FFMPEG_FAILED");
         }
     }
 }
Exemplo n.º 20
0
function GAL_getImageInfo($folder, $file)
{
    $thumbFolder = $folder . $GLOBALS['GAL_thumbnail_folder'];
    $fileName = $file . '.meta';
    $ret = array();
    $ret['dateLastModified'] = -1;
    clearstatcache();
    if (!file_exists($thumbFolder . $fileName)) {
        $dateLastModified = @filemtime($folder . $file);
        $f = @fopen($thumbFolder . $fileName, 'wb');
        if (is_resource($f)) {
            fwrite($f, $dateLastModified);
            fclose($f);
        }
        $ret['dateLastModified'] = $dateLastModified;
    } else {
        $f = @fopen($thumbFolder . $fileName, 'rb');
        if (is_resource($f)) {
            $dateLastModified = trim(@fread($f, filesize($thumbFolder . $fileName)));
            fclose($f);
        }
        $ret['dateLastModified'] = $dateLastModified;
    }
    flush();
    return $ret;
}
Exemplo n.º 21
0
/**
 * Return array of filenames to convert
 * @param string $dirName
 * @return mixed
 */
function getFileList($dirName = null)
{
    if (!is_string($dirName)) {
        return false;
    }
    if (!is_dir($dirName)) {
        return false;
    }
    if (!is_readable($dirName)) {
        return false;
    }
    clearstatcache();
    $ret_ar = array();
    if (!($dh = opendir($dirName))) {
        return false;
    }
    while (false !== ($file = readdir($dh))) {
        if ($file == '..' or $file == '.') {
            continue;
        }
        $cur_file = $dirName . '/' . $file;
        if (is_dir($cur_file)) {
            $tmp_ar = getFileList($cur_file);
            if (is_array($tmp_ar)) {
                $ret_ar = array_merge($ret_ar, $tmp_ar);
            }
        }
        $ret_ar[] = $cur_file;
    }
    closedir($dh);
    natcasesort($ret_ar);
    return $ret_ar;
}
Exemplo n.º 22
0
function initConfig($db_host, $db_user, $db_pass, $db_prefix, $db_name)
{
    $code = "return array(\n\t    'VAR_PAGE'=>'p',\n\t    'PAGE_SIZE'=>15,\n\t\t'DB_TYPE'=>'mysql',\n\t    'DB_HOST'=>'" . $db_host . "',\n\t    'DB_NAME'=>'" . $db_name . "',\n\t    'DB_USER'=>'" . $db_user . "',\n\t    'DB_PWD'=>'" . $db_pass . "',\n\t    'DB_PREFIX'=>'" . $db_prefix . "',\n\t    'DEFAULT_C_LAYER' =>  'Action',\n\t    'DEFAULT_CITY' => '440100',\n\t    'DATA_CACHE_SUBDIR'=>true,\n        'DATA_PATH_LEVEL'=>2, \n\t    'SESSION_PREFIX' => 'WSTMALL',\n        'COOKIE_PREFIX'  => 'WSTMALL',\n\t\t'LOAD_EXT_CONFIG' => 'wst_config'\n\t)";
    $code = "<?php\n " . $code . ";\n?>";
    file_put_contents(INSTALL_ROOT . "/Apps/Common/Conf/config.php", $code);
    clearstatcache();
}
Exemplo n.º 23
0
 public function postflight($type, $parent)
 {
     // Clear Joomla system cache.
     /** @var JCache|JCacheController $cache */
     $cache = JFactory::getCache();
     $cache->clean('_system');
     // Clear Gantry5 cache.
     $path = JFactory::getConfig()->get('cache_path', JPATH_SITE . '/cache') . '/gantry5';
     if (is_dir($path)) {
         JFolder::delete($path);
     }
     // Make sure that PHP has the latest data of the files.
     clearstatcache();
     // Remove all compiled files from opcode cache.
     if (function_exists('opcache_reset')) {
         @opcache_reset();
     } elseif (function_exists('apc_clear_cache')) {
         @apc_clear_cache();
     }
     if ($type == 'uninstall') {
         return true;
     }
     /** @var JInstallerAdapter $parent */
     $manifest = $parent->getManifest();
     // Enable and lock extensions to prevent uninstalling them individually.
     $this->prepareExtensions($manifest, 1);
     // Make sure that all file formats used by Gantry 5 are editable from template manager.
     $this->adjustTemplateSettings();
     return true;
 }
Exemplo n.º 24
0
 /**
  * Read the contents of a file
  *
  * @param string $filename The full file path
  * @param boolean $incpath Use include path
  * @param int $amount Amount of file to read
  * @param int $chunksize Size of chunks to read
  * @param int $offset Offset of the file
  * @return mixed Returns file contents or boolean False if failed
  * @since 1.5
  */
 function read($filename, $incpath = false, $amount = 0, $chunksize = 8192, $offset = 0)
 {
     // Initialize variables
     $data = null;
     if ($amount && $chunksize > $amount) {
         $chunksize = $amount;
     }
     if (false === ($fh = fopen($filename, 'rb', $incpath))) {
         JError::raiseWarning(21, 'extFile::read: ' . JText::_('Unable to open file') . ": '{$filename}'");
         return false;
     }
     clearstatcache();
     if ($offset) {
         fseek($fh, $offset);
     }
     if ($fsize = @filesize($filename)) {
         if ($amount && $fsize > $amount) {
             $data = fread($fh, $amount);
         } else {
             $data = fread($fh, $fsize);
         }
     } else {
         $data = '';
         $x = 0;
         // While its:
         // 1: Not the end of the file AND
         // 2a: No Max Amount set OR
         // 2b: The length of the data is less than the max amount we want
         while (!feof($fh) && (!$amount || strlen($data) < $amount)) {
             $data .= fread($fh, $chunksize);
         }
     }
     fclose($fh);
     return $data;
 }
function w_rmdir_recursive_inner($path)
{
    # avoid opening a handle on the dir in case that impacts
    # delete latency on windows
    if (@rmdir($path) || @unlink($path)) {
        return true;
    }
    clearstatcache();
    if (is_dir($path)) {
        # most likely failure reason is that the dir is not empty
        $kids = @scandir($path);
        if (is_array($kids)) {
            foreach ($kids as $kid) {
                if ($kid == '.' || $kid == '..') {
                    continue;
                }
                w_rmdir_recursive($path . DIRECTORY_SEPARATOR . $kid);
            }
        }
        if (is_dir($path)) {
            return @rmdir($path);
        }
    }
    if (is_file($path)) {
        return unlink($path);
    }
    return !file_exists($path);
}
Exemplo n.º 26
0
 /**
  * Called when we think the caches are getting messy
  **/
 function clean_dir()
 {
     clearstatcache();
     // Clean the activity stream
     $cache = ABSPATH . 'wp-content/uploads/activity/';
     if (is_dir($cache)) {
         $d = dir($cache);
         while ($entry = $d->read()) {
             if ($entry != "." && $entry != "..") {
                 unlink($cache . $entry);
             }
         }
         $d->close();
     }
     // Clean the WiPi cache
     $cache = TEMPLATEPATH . '/app/cache/';
     if (is_dir($cache)) {
         $d = dir($cache);
         while ($entry = $d->read()) {
             if ($entry != "." && $entry != "..") {
                 unlink($cache . $entry);
             }
         }
         $d->close();
     }
 }
Exemplo n.º 27
0
 /**
  * @group internet
  * @group slow
  */
 public function test_recache()
 {
     global $conf;
     $conf['fetchsize'] = 500 * 1024;
     //500kb
     $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png', 'png', 5);
     $this->assertTrue($local !== false);
     $this->assertFileExists($local);
     // remember time stamp
     $time = filemtime($local);
     clearstatcache(false, $local);
     sleep(1);
     // fetch again and make sure we got a cache file
     $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png', 'png', 5);
     clearstatcache(false, $local);
     $this->assertTrue($local !== false);
     $this->assertFileExists($local);
     $this->assertEquals($time, filemtime($local));
     clearstatcache(false, $local);
     sleep(6);
     // fetch again and make sure we got a new file
     $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png', 'png', 5);
     clearstatcache(false, $local);
     $this->assertTrue($local !== false);
     $this->assertFileExists($local);
     $this->assertNotEquals($time, filemtime($local));
     unlink($local);
 }
Exemplo n.º 28
0
 /**
  * {@inheritdoc}
  */
 public function exists($key)
 {
     $this->initialize();
     $url = $this->sftp->getUrl($this->computePath($key));
     clearstatcache();
     return file_exists($url);
 }
Exemplo n.º 29
0
 /**
  * 写入缓存
  * @access public
  * @param string $name 缓存变量名
  * @param mixed $value  存储数据
  * @param int $expire  有效时间 0为永久
  * @return boolean
  */
 public function set($name, $value, $expire = null)
 {
     if (is_null($expire)) {
         $expire = $this->options['expire'];
     }
     $filename = $this->getFileName($name);
     $data = serialize($value);
     //是否数据压缩
     if ($this->options['compress'] && function_exists('gzcompress')) {
         //数据压缩
         $data = gzcompress($data, 3);
     }
     //是否数据校验
     if ($this->options['check']) {
         $check = md5($data);
     } else {
         $check = '';
     }
     $data = "<?php\n//" . sprintf('%012d', $expire) . $check . $data . "\n?>";
     $result = file_put_contents($filename, $data);
     if ($result) {
         //            if($this->options['length']>0) {
         //                // 记录缓存队列
         //                $this->queue($name);
         //            }
         clearstatcache();
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 30
0
 protected function get_file_size($file_path, $clear_stat_cache = false)
 {
     if ($clear_stat_cache) {
         clearstatcache();
     }
     return $this->fix_integer_overflow(filesize($file_path));
 }