/** * Execute the console command. * * @return void * * @throws \Exception */ public function fire() { $uploadPath = env('UPLOAD_DIR', 'uploads'); // Use UPLOAD_DIR either as an absolute path, or relative to the base path if (!($path = realpath($uploadPath))) { $path = base_path($uploadPath); } $importedSomething = false; foreach (scandir($path) as $file) { if (in_array($file, ['.', '..', '.gitignore', '.gitkeep'])) { continue; } $version = $this->import($file, $path); if ($version) { $importedSomething = true; $identifier = $version->package->identifier; $versionNumber = $version->name; $this->info("Imported \"<comment>{$identifier}</comment>\" (@ {$versionNumber})"); // Make sure the directory exists if (!file_exists(dirname($version->storagePath))) { mkdir(dirname($version->storagePath)); } rename($path . '/' . $file, $version->storagePath); } } if ($importedSomething) { if (Cache::has('xml.renderedPath')) { unlink(Cache::pull('xml.renderedPath')); } } else { $this->info('No files found to import.'); } }
/** * Test some software's and respond to the user * * @return \Illuminate\View\View * @throws \Exception */ public function test() { try { // Testing Database (MySQL) DB::connection()->getDatabaseName(); // Testing Cache (Redis) Cache::pull('test'); return view('welcome'); } catch (Exception $e) { echo $e->getMessage(); } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $data['title'] = $request->input('title'); $data['seo_title'] = $request->input('seo_title'); $data['destination_id'] = $request->input('destination_id'); $data['slug'] = str_slug($request->input('slug')); $data['description'] = $request->input('description'); $data['cover_image'] = $request->input('cover_image'); $data['begin_date'] = $request->input('begin_date'); $data['end_date'] = $request->input('end_date'); $data['content'] = $request->input('content'); $data['score'] = $request->input('score'); Cache::pull("travel.detail.{$data['slug']}"); $this->travel->where('id', $id)->update($data); //更新游记触达事件 event(new TravelsWasUpdated($data)); return redirect()->back(); }
public function pull($key) { return Cache::pull($key); }
public function pullCache() { Cache::pull($this->getCacheKey()); }
/** * Executes the commands for a step. * * @param DeployStep $step * @throws \RuntimeException */ private function runStep(DeployStep $step) { foreach ($step->servers as $log) { $log->status = ServerLog::RUNNING; $log->started_at = date('Y-m-d H:i:s'); $log->save(); $server = $log->server; $failed = false; $cancelled = false; try { $this->sendFilesForStep($step, $log); $process = $this->buildScript($step, $server); if (!empty($process)) { $output = ''; $process->run(function ($type, $output_line) use(&$output, &$log, $process, $step) { if ($type === \Symfony\Component\Process\Process::ERR) { $output .= $this->logError($output_line); } else { $output .= $this->logSuccess($output_line); } $log->output = $output; $log->save(); // If there is a cache key, kill the process but leave the key if ($step->stage <= Stage::DO_ACTIVATE && Cache::has($this->cache_key)) { $process->stop(0, SIGINT); $output .= $this->logError('SIGINT'); } }); if (!$process->isSuccessful()) { $failed = true; } $log->output = $output; } } catch (\Exception $e) { $log->output .= $this->logError('[' . $server->ip_address . ']: ' . $e->getMessage()); $failed = true; } $log->status = $failed ? ServerLog::FAILED : ServerLog::COMPLETED; // Check if there is a cache key and if so abort if (Cache::pull($this->cache_key) !== null) { // Only allow aborting if the release has not yet been activated if ($step->stage <= Stage::DO_ACTIVATE) { $log->status = ServerLog::CANCELLED; $cancelled = true; $failed = false; } } $log->finished_at = date('Y-m-d H:i:s'); $log->save(); // Throw an exception to prevent any more tasks running if ($failed) { throw new \RuntimeException('Failed'); } // This is a messy way to do it if ($cancelled) { throw new \RuntimeException('Cancelled'); } } }
public function destroyClientCacheSP($header_id, $detail_id) { $key = 'clients_' . $header_id; if (Cache::has($key)) { $clients = Cache::pull($key); if (!is_null($clients)) { $clients = json_decode($clients, true); $client = array_shift($clients); if ($client === $detail_id) { $this->setClientCacheSP($header_id, $clients); } if (count($clients) > 0) { return true; } } } return false; }
/** * Get an email address from supplied token. * * @param $token * @return mixed */ public function getEmailFromToken($token) { $newEmail = Cache::pull('email_confirmation_' . $token, false); if ($newEmail) { Cache::forget('email_change_' . $newEmail); } return $newEmail; }