Esempio n. 1
0
 /**
  * Set the cached stat info for a file path.
  * Negatives (404s) are not cached. By not caching negatives, we can skip cache
  * salting for the case when a file is created at a path were there was none before.
  *
  * @param string $path Storage path
  * @param array $val Stat information to cache
  */
 protected final function setFileCache($path, array $val)
 {
     $path = FileBackend::normalizeStoragePath($path);
     if ($path === null) {
         return;
         // invalid storage path
     }
     $mtime = ConvertibleTimestamp::convert(TS_UNIX, $val['mtime']);
     $ttl = $this->memCache->adaptiveTTL($mtime, 7 * 86400, 300, 0.1);
     $key = $this->fileCacheKey($path);
     // Set the cache unless it is currently salted.
     $this->memCache->set($key, $val, $ttl);
 }
Esempio n. 2
0
 public function decodeExpiry($expiry, $format = TS_MW)
 {
     if ($expiry == '' || $expiry == 'infinity' || $expiry == $this->getInfinity()) {
         return 'infinity';
     }
     return ConvertibleTimestamp::convert($format, $expiry);
 }
 /**
  * Format an invalid timestamp.
  * @covers ConvertibleTimestamp::convert
  */
 public function testConvertInvalid()
 {
     $this->assertSame(false, ConvertibleTimestamp::convert('Not a timestamp', 0));
 }
Esempio n. 4
0
 /**
  * function to validate date properties, and convert to (partial) Exif format.
  *
  * Dates can be one of the following formats:
  * YYYY
  * YYYY-MM
  * YYYY-MM-DD
  * YYYY-MM-DDThh:mmTZD
  * YYYY-MM-DDThh:mm:ssTZD
  * YYYY-MM-DDThh:mm:ss.sTZD
  *
  * @param array $info Information about current property
  * @param mixed &$val Current value to validate. Converts to TS_EXIF as a side-effect.
  *    in cases where there's only a partial date, it will give things like
  *    2011:04.
  * @param bool $standalone If this is a simple property or array
  */
 public function validateDate($info, &$val, $standalone)
 {
     if (!$standalone) {
         // this only validates standalone properties, not arrays, etc
         return;
     }
     $res = [];
     // @codingStandardsIgnoreStart Long line that cannot be broken
     if (!preg_match('/^([0-3]\\d{3})(?:-([01]\\d)(?:-([0-3]\\d)(?:T([0-2]\\d):([0-6]\\d)(?::([0-6]\\d)(?:\\.\\d+)?)?([-+]\\d{2}:\\d{2}|Z)?)?)?)?$/D', $val, $res)) {
         // @codingStandardsIgnoreEnd
         $this->logger->info(__METHOD__ . " Expected date but got {$val}");
         $val = null;
     } else {
         /*
          * $res is formatted as follows:
          * 0 -> full date.
          * 1 -> year, 2-> month, 3-> day, 4-> hour, 5-> minute, 6->second
          * 7-> Timezone specifier (Z or something like +12:30 )
          * many parts are optional, some aren't. For example if you specify
          * minute, you must specify hour, day, month, and year but not second or TZ.
          */
         /*
          * First of all, if year = 0000, Something is wrongish,
          * so don't extract. This seems to happen when
          * some programs convert between metadata formats.
          */
         if ($res[1] === '0000') {
             $this->logger->info(__METHOD__ . " Invalid date (year 0): {$val}");
             $val = null;
             return;
         }
         if (!isset($res[4])) {
             // hour
             // just have the year month day (if that)
             $val = $res[1];
             if (isset($res[2])) {
                 $val .= ':' . $res[2];
             }
             if (isset($res[3])) {
                 $val .= ':' . $res[3];
             }
             return;
         }
         if (!isset($res[7]) || $res[7] === 'Z') {
             // if hour is set, then minute must also be or regex above will fail.
             $val = $res[1] . ':' . $res[2] . ':' . $res[3] . ' ' . $res[4] . ':' . $res[5];
             if (isset($res[6]) && $res[6] !== '') {
                 $val .= ':' . $res[6];
             }
             return;
         }
         // Extra check for empty string necessary due to TZ but no second case.
         $stripSeconds = false;
         if (!isset($res[6]) || $res[6] === '') {
             $res[6] = '00';
             $stripSeconds = true;
         }
         // Do timezone processing. We've already done the case that tz = Z.
         // We know that if we got to this step, year, month day hour and min must be set
         // by virtue of regex not failing.
         $unix = ConvertibleTimestamp::convert(TS_UNIX, $res[1] . $res[2] . $res[3] . $res[4] . $res[5] . $res[6]);
         $offset = intval(substr($res[7], 1, 2)) * 60 * 60;
         $offset += intval(substr($res[7], 4, 2)) * 60;
         if (substr($res[7], 0, 1) === '-') {
             $offset = -$offset;
         }
         $val = ConvertibleTimestamp::convert(TS_EXIF, $unix + $offset);
         if ($stripSeconds) {
             // If seconds weren't specified, remove the trailing ':00'.
             $val = substr($val, 0, -3);
         }
     }
 }