private function _getHtml($file) { $obj = new Snapshot(); $obj->binary = file_get_contents($file); $chunks = explode('/', $file); $fileName = array_pop($chunks); $html = $fileName . "\n\r" . $obj->readNoTags(); return $html; }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $snapshot = Snapshot::find($id); if ($snapshot['item_status'] == 'ready') { return view('snapshot.show', compact('snapshot')); } return view('snapshot.pending', compact('snapshot')); }
/** * @param Organization $organization * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function organizationPage(Organization $organization) { $workers = null; $snapshot = Snapshot::where('organization_id', $organization->id)->orderBy('id', 'desc')->first(); if (!is_null($snapshot)) { $workers = Worker::where('snapshot_id', $snapshot->id)->get(); $workers = Worker::structure($workers); } $this->getCounters(); return view('site.organization', ['organization' => $organization, 'snapshot' => $snapshot, 'workers' => $workers, 'fixed' => true]); }
public static function create(Url $url, $response) { $webpage = Webpage::where('Url', (string) $url)->first(); if (!$webpage) { return; } // dd( $webpage ); $statusCode = $response ? $response->getStatusCode() : self::UNRESPONSIVE_HOST; $html = ''; if (self::isHtml($response)) { $html = $response->getBody()->getContents(); $html = FilterContent::make($html); } Snapshot::create(['html' => $html, 'status_code' => $statusCode, 'webpage_id' => $webpage->id, 'hash' => md5($html)]); }
/** * Execute the job. * * @return void */ public function handle() { $path = storage_path('app/tmp/') . $this->id . '/'; $safe_url = escapeshellcmd($this->url); $user_agent = env('SCRAPER_USER_AGENT'); $return_status = -1; $output = []; // Download website $result = exec("httrack '" . $safe_url . "' -w -O '" . $path . "' -z --depth=1 --user-agent='" . $user_agent . "' --near --urlhack -s0 -N1099", $output, $return_status); // Get page title $page_title = self::getPageTitle($this->url); // Upload to S3 $s3 = AWS::createClient('s3'); $s3->uploadDirectory($path, 'permalinker-snapshots', $this->id . '/'); // Update database Snapshot::fillItem($this->id, $page_title); // Delete temporary directory File::deleteDirectory($path); }
/** * Run the migrations. * * @return void */ public function up() { Schema::create('product_snapshot', function (Blueprint $table) { $table->increments('id'); $table->integer('product_id')->default(0); $table->integer('snapshot_id')->default(0); $table->timestamps(); }); // rows have been stored in a comma delimited list, get them out and store in db $snapshots = Snapshot::orderBy('created_at', 'asc')->get(); foreach ($snapshots as $snapshot) { if ($snapshot->snapshot_products != '') { $products = explode(',', $snapshot->snapshot_products); if (count($products)) { foreach ($products as $product) { $snapshot->products()->attach($product); } } } } }
/** * Удаление организации * @param Organization $organization * @return \Illuminate\Http\RedirectResponse * @throws \Exception */ public function delete(Organization $organization) { // удаляем подразделения Organization::where('parent_id', $organization->id)->delete(); // удаляем сотрудников Worker::where('organization_id', $organization->id)->delete(); Snapshot::where('organization_id', $organization->id)->delete(); // удаляем саму организацию $organization->delete(); return redirect()->route('admin::organization'); }
/** * Destroy the given snapshots. * * @param Request $request * @param Task $task * @return Response */ public function destroy(Request $request, Snapshot $snapshot) { //$this->authorize('destroy', $product); $snapshot->delete(); return redirect('/snapshot'); }
/** * Добавляем в БД всех сотрудников организации * * @param Request $request * @param Organization $organization */ public function pushWorkers(Request $request, Organization $organization) { $workers = []; // создаем метку, которая привязывается ко всем сотрудникам // и сохраняем название организации и едрпоу, на тот случай если они потом изменяться $snapshot = new Snapshot(); $snapshot->name = $organization->fullName; $snapshot->edrpou = $organization->edrpou; $snapshot->date = Carbon::parse($request->get('date')); $snapshot->organization()->associate($organization); $snapshot->save(); $organization->snapshot()->associate($snapshot); $organization->save(); // разделы foreach ($request->get('workers') as $departmentName => $departmentData) { if ($departmentName == 'main') { $departmentName = ''; } if (isset($departmentData['workers'])) { foreach ($departmentData['workers'] as $workerData) { $this->_createWorker($workers, $workerData, $snapshot, $organization, $departmentName); } } // подразделы if (isset($departmentData['sub'])) { foreach ($departmentData['sub'] as $subDepartmentName => $workersData) { foreach ($workersData as $workerData) { $this->_createWorker($workers, $workerData, $snapshot, $organization, $departmentName, $subDepartmentName); } } } } $snapshot->count = count($workers); $snapshot->save(); Worker::insert($workers); // индексуруем работников $newWorkers = Worker::where('snapshot_id', $snapshot->id)->get(); $newWorkers->addToIndex(); }