protected function checkNotifications(PathRecord $record)
 {
     $path = $record->getPath();
     $parent = $path->getParent();
     // probably in the root dir
     if ($parent === null) {
         return;
     }
     $rootRecord = $parent->loadRecord();
     if (!$rootRecord) {
         return;
     }
     // check if parent has a series assigned
     if (!$rootRecord->series) {
         return;
     }
     // find users who are linked to this series (via user_series) and who don't already
     // have a notification for this path record
     $users = $rootRecord->series->users()->whereHas('notifications', function ($q) use($record) {
         $q->where('path_record_id', '=', $record->id);
     }, '<', 1)->get();
     // add notifications for users
     foreach ($users as $user) {
         Notification::createForUserRecord($user, $record);
     }
 }
示例#2
0
 public function loadRecord()
 {
     if (!$this->record) {
         $this->record = PathRecord::getForPath($this);
     }
     return $this->record;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $target = $this->option('path');
     PathRecord::orderBy('directory', 'desc')->chunk(200, function ($pathRecords) use($target) {
         foreach ($pathRecords as $pathRecord) {
             if ($pathRecord->path === '/') {
                 continue;
             }
             $fullPath = $target . '/' . $pathRecord->path;
             if (file_exists($fullPath)) {
                 continue;
             }
             if ($pathRecord->directory) {
                 try {
                     mkdir($fullPath, 0777, true);
                     //printf("%s\n", $fullPath);
                 } catch (Exception $e) {
                     var_dump($fullPath);
                 }
             } else {
                 try {
                     touch($fullPath);
                 } catch (Exception $e) {
                     var_dump($fullPath);
                 }
             }
         }
     });
 }
示例#4
0
 public static function boot()
 {
     parent::boot();
     // observer for on-created notifications
     PathRecord::observe(new PathRecordNotifications());
     PathRecord::updating(function ($record) {
         $record->deleteCache();
     });
 }
示例#5
0
 public static function searchPaths($keyword, &$count)
 {
     $conn = self::getSphinxConnection();
     $query = SphinxQL::create($conn)->select('*')->from('mangaindex_paths')->where('directory', '=', 1)->limit(0, 100);
     $escaped = $query->halfEscapeMatch($keyword);
     $escaped = str_replace('?', '\\?', $escaped);
     // "?" behaves strangely and doesn't get escaped by the above
     $query->match('*', $escaped);
     $result = $query->execute();
     $ids = self::getIds($result);
     $metaResult = Helper::create($conn)->showMeta()->execute();
     $meta = self::sortMeta($metaResult);
     $count = $meta['total_found'];
     if (count($ids) > 0) {
         $records = PathRecord::whereIn('id', $ids)->get();
         return $records;
     } else {
         return array();
     }
 }
示例#6
0
 public function muid($muId)
 {
     $records = PathRecord::with('series.facets')->whereHas('series', function ($q) use($muId) {
         $q->whereMuId($muId);
     })->get();
     $export = array();
     foreach ($records as $record) {
         if (strpos($record->path, '/Manga/') === 0) {
             // Skip paths
             if (strpos($record->path, '/Manga/Non-English') === 0) {
                 continue;
             } else {
                 $path = $record->getPath();
                 if ($path->exists()) {
                     $export[] = $record->toArray();
                 }
             }
         }
     }
     return Response::json(array('result' => true, 'data' => $export));
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $xml = new XMLWriter();
     $xml->openMemory();
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement('urlset');
     $xml->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     PathRecord::chunk(200, function ($records) use($xml) {
         foreach ($records as $record) {
             $path = $record->getPath();
             if ($path->exists()) {
                 $url = URL::to($path->getUrl());
                 $xml->startElement('url');
                 $xml->writeElement('loc', $url);
                 $xml->endElement();
             }
         }
     });
     $xml->endElement();
     $xml->endDocument();
     echo $xml->flush();
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $dryRun = $this->option('dry-run');
     if (!is_bool($dryRun)) {
         if ($dryRun === 'true') {
             $dryRun = true;
         } elseif ($dryRun === 'false') {
             $dryRun = false;
         } else {
             $this->error($dryRun . ' is not a valid value for --dry-run');
             return;
         }
     }
     $pageSize = 1000;
     $page = 0;
     $count = 0;
     $size = 0;
     while (true) {
         $records = PathRecord::take($pageSize)->offset($page * $pageSize)->get();
         foreach ($records as $record) {
             $path = $record->getPath();
             if (!$path->exists()) {
                 $this->line($record->path);
                 $count++;
                 $size += $record->size;
                 if (!$dryRun) {
                     $record->delete();
                 }
             }
         }
         if ($records->count() < $pageSize) {
             break;
         }
         $page++;
     }
     $this->info(sprintf('%d deleted (%s)', $count, DisplaySize::format($size)));
 }
 protected function getRecentRecords()
 {
     $records = PathRecord::whereDirectory(false)->whereRaw('left(path, 5) in ("/Mang", "/Raws")')->orderBy('modified', 'desc')->take(1000)->get();
     return $records;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $dryRunOpt = $this->option('dry-run');
     if ($dryRunOpt === true) {
         $dryRun = true;
     } elseif ($dryRunOpt === 'true') {
         $dryRun = true;
     } elseif ($dryRunOpt === 'false') {
         $dryRun = false;
     } else {
         $this->error('Invalid value for --dry-run');
         return;
     }
     $sourceDirectories = array('/Manga/_Autouploads/AutoUploaded from Assorted Sources');
     $movedFiles = array();
     // Loop through each auto uploads parent folder
     foreach ($sourceDirectories as $sourceDirectory) {
         $sourcePath = Path::fromRelative($sourceDirectory);
         if (!$sourcePath->exists()) {
             $this->error('Source path does not exist: ' . $sourceDirectory);
             continue;
         }
         // Loop through each series dir in the auto uploads folder
         $sourceChildren = $sourcePath->getChildren();
         foreach ($sourceChildren as $sourceChild) {
             $sourceName = $sourceChild->getFilename();
             // Look for matching path records by series name
             $matchedRecords = PathRecord::join('series', 'series.id', '=', 'path_records.series_id')->join('facet_series', 'facet_series.series_id', '=', 'series.id')->join('facets', 'facets.id', '=', 'facet_series.facet_id')->where('facet_series.type', '=', 'title')->where('facets.name', '=', $sourceName)->get();
             // Found a match
             if (count($matchedRecords) === 1) {
                 $matchedRecord = $matchedRecords->first();
                 $matchedPath = $matchedRecord->getPath();
                 $seriesChildren = $sourceChild->getChildren();
                 foreach ($seriesChildren as $seriesChild) {
                     if ($seriesChild->isDir()) {
                         $this->error('ERROR: Sub-directory in source series: ' . $seriesChild->getPathName());
                         continue;
                     }
                     $srcFile = $seriesChild->getPathName();
                     $dstFile = $matchedPath->getPathName() . '/' . $seriesChild->getFilename();
                     if (file_exists($dstFile)) {
                         if (filesize($srcFile) === filesize($dstFile) && md5_file($srcFile) === md5_file($dstFile)) {
                             $dstFile = Path::fromRelative('/Admin cleanup')->getPathName() . '/' . $seriesChild->getFilename();
                         } else {
                             $this->error('ERROR: Destination file already exists: ' . $dstFile);
                             continue;
                         }
                     }
                     $movedFiles[] = array('src' => $srcFile, 'dst' => $dstFile);
                     $this->info($srcFile . ' -> ' . $dstFile);
                 }
             } else {
                 $row = DB::connection('mangaupdates')->table('namelist')->where('name', '=', $sourceName)->orWhere('fsSafeName', '=', $sourceName)->first();
                 $seriesId = null;
                 if ($row) {
                     $series = Series::where('mu_id', '=', $row->mu_id)->first();
                     if (!$series) {
                         $series = new Series();
                         $series->mu_id = $row->mu_id;
                         $series->save();
                     }
                     $seriesId = $series->id;
                 }
                 $bucket = '# - F';
                 $chr = strtoupper($sourceName[0]);
                 if ($chr >= 'N' && $chr <= 'Z') {
                     $bucket = 'N - Z';
                 } elseif ($chr >= 'G' && $chr <= 'M') {
                     $bucket = 'G - M';
                 }
                 $dstSeries = Path::fromRelative('/Manga/' . $bucket)->getPathName() . '/' . $sourceName;
                 if (file_exists($dstSeries)) {
                     $seriesChildren = $sourceChild->getChildren();
                     foreach ($seriesChildren as $seriesChild) {
                         if ($seriesChild->isDir()) {
                             $this->error('ERROR: Sub-directory in source series: ' . $seriesChild->getPathName());
                             continue;
                         }
                         $srcFile = $seriesChild->getPathName();
                         $dstFile = $dstSeries . '/' . $seriesChild->getFilename();
                         if (file_exists($dstFile)) {
                             if (filesize($srcFile) === filesize($dstFile) && md5_file($srcFile) === md5_file($dstFile)) {
                                 $dstFile = Path::fromRelative('/Admin cleanup')->getPathName() . '/' . $seriesChild->getFilename();
                             } else {
                                 $this->error('ERROR: Destination file already exists: ' . $dstFile);
                                 continue;
                             }
                         }
                         $movedFiles[] = array('src' => $srcFile, 'dst' => $dstFile);
                         $this->info($srcFile . ' -> ' . $dstFile);
                     }
                 } else {
                     $movedFiles[] = array('src' => $sourceChild->getPathName(), 'dst' => $dstSeries);
                     $this->info($sourceChild->getPathName() . ' -> ' . $dstSeries);
                 }
             }
         }
     }
     if (!$dryRun) {
         foreach ($movedFiles as $move) {
             try {
                 if (is_file($move['src'])) {
                     $dir = dirname($move['src']);
                     if (!is_dir($dir)) {
                         mkdir($dir, 0777, true);
                     }
                 }
                 rename($move['src'], $move['dst']);
             } catch (ErrorException $exception) {
                 $this->error('ERROR: rename() failed: ' . $seriesChild->getPathName() . ' -> ' . $dstFile . ' ' . $exception->getMessage());
             }
         }
     }
     file_put_contents(storage_path() . '/logs/merge-auto-uploads-' . date('Y-m-d-H-i-s'), serialize($movedFiles));
     if (!$dryRun) {
         // Delete empty source folders
         foreach ($sourceDirectories as $sourceDirectory) {
             $sourcePath = Path::fromRelative($sourceDirectory);
             if (!$sourcePath->exists()) {
                 $this->error('Source path does not exist: ' . $sourceDirectory);
                 continue;
             }
             $sourceChildren = $sourcePath->getChildren();
             foreach ($sourceChildren as $sourceChild) {
                 if (count($sourceChild->getChildren()) === 0) {
                     rmdir($sourceChild->getPathName());
                 }
             }
         }
     }
 }
示例#11
0
 public function report()
 {
     $recordId = Input::get('record');
     $reason = Input::get('reason');
     if (!$reason) {
         Session::flash('error', 'Please enter a report reason!');
         return Redirect::back();
     }
     $count = Report::where('path_record_id', '=', $recordId)->count();
     if ($count > 0) {
         Session::flash('error', 'This path has already been reported');
         return Redirect::back();
     }
     // load record
     $record = PathRecord::findOrFail($recordId);
     if ($record->locked) {
         Session::flash('error', 'You cannot report this directory!');
         return Redirect::back();
     }
     $report = new Report();
     $report->path_record_id = $record->id;
     $report->path = $record->path;
     $report->reason = $reason;
     $user = Auth::user();
     if ($user) {
         $report->user_id = $user->id;
     }
     $report->save();
     Session::flash('success', 'Report submitted');
     return Redirect::back();
 }