コード例 #1
1
 /**
  * Проверка файлов на различия, проверяется по размеру файла и наличие файла в ФС
  * @retun array
  */
 public function checkFiles()
 {
     $cachedFiles = Cache::remember(static::CACHE_KEY, Carbon::now()->addHours(6), function () {
         $response = $this->request('https://api.github.com/repos/:rep/git/trees/:branch?recursive=true');
         $response = json_decode($response, true);
         $files = ['new_files' => [], 'diff_files' => [], 'third_party_plugins' => []];
         if (isset($response['tree'])) {
             foreach ($response['tree'] as $row) {
                 $filePath = base_path($row['path']);
                 if (!file_exists($filePath)) {
                     $files['new_files'][] = $this->getFileUrlByPath($row['path']);
                     continue;
                 }
                 $fileSize = filesize($filePath);
                 if (isset($row['size']) and $fileSize != $row['size']) {
                     $diff = $fileSize - $this->countFileLines($filePath) - $row['size'];
                     if ($diff > 1 or $diff < -1) {
                         $files['diff_files'][] = ['diff' => Text::bytes($diff), 'path' => $row['path'], 'url' => $this->buildRemoteUrl('https://raw.githubusercontent.com/:rep/:branch/' . $row['path'])];
                     }
                 }
             }
             return $files;
         }
     });
     return $cachedFiles;
 }
コード例 #2
0
 /**
  * @param string $uri
  *
  * @return string|bool
  */
 public static function findSimilar($uri)
 {
     if (empty($uri)) {
         return false;
     }
     $uriSlugs = array_merge([''], preg_split('/\\//', $uri, -1, PREG_SPLIT_NO_EMPTY));
     $slugs = DB::table('pages')->select('id', 'slug')->whereIn('status_id', config('pages.similar.find_in_statuses', []));
     if (config('pages.check_date')) {
         $slugs->where('published_at', '<=', DB::raw('NOW()'));
     }
     $slugs = $slugs->get()->lists('slug', 'id')->all();
     $newSlugs = [];
     foreach ($uriSlugs as $slug) {
         if (in_array($slug, $slugs)) {
             $newSlugs[] = $slug;
             continue;
         }
         $similarPages = Text::similarWord($slug, $slugs);
         if (!empty($similarPages)) {
             $pageId = key($similarPages);
             $page = static::findById($pageId);
             $newSlugs[] = $page->getSlug();
         }
     }
     if (!config('pages.similar.return_parent_page') and count($uriSlugs) != count($newSlugs)) {
         return false;
     }
     $uri = implode('/', $newSlugs);
     $page = static::find($uri);
     return $page ? $uri : false;
 }
コード例 #3
0
ファイル: File.php プロジェクト: KodiComponents/module-core
 /**
  * @return int
  */
 public function getSize()
 {
     if ($this->isNew()) {
         $size = 0;
     } else {
         $size = $this->file->getSize();
     }
     return Text::bytes($size);
 }