@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | public function sanitizeForQuery($value) |
96 | 96 | { |
97 | 97 | $chars = preg_quote('\\+-&|!(){}[]^~*?:'); |
98 | - $value = preg_replace('/([' . $chars . '])/', '\\\\\1', $value); |
|
98 | + $value = preg_replace('/(['.$chars.'])/', '\\\\\1', $value); |
|
99 | 99 | |
100 | 100 | return $value; |
101 | 101 | // |
@@ -127,20 +127,20 @@ discard block |
||
127 | 127 | } |
128 | 128 | if ($request->has('collection')) { |
129 | 129 | $col = Collection::findOrFail($request->collection); |
130 | - $query[] = 'collections:"' . $this->sanitizeForQuery($col->name) . '"'; |
|
130 | + $query[] = 'collections:"'.$this->sanitizeForQuery($col->name).'"'; |
|
131 | 131 | } |
132 | 132 | if ($request->has('subject')) { |
133 | - $query[] = '(subjects.noubomn.prefLabel:"' . $this->sanitizeForQuery($request->subject) . '"' . |
|
134 | - ' OR subjects.NOTrBIB.prefLabel:"' . $this->sanitizeForQuery($request->subject) . '"' . |
|
135 | - ' OR genres.noubomn.prefLabel:"' . $this->sanitizeForQuery($request->subject) . '")'; |
|
133 | + $query[] = '(subjects.noubomn.prefLabel:"'.$this->sanitizeForQuery($request->subject).'"'. |
|
134 | + ' OR subjects.NOTrBIB.prefLabel:"'.$this->sanitizeForQuery($request->subject).'"'. |
|
135 | + ' OR genres.noubomn.prefLabel:"'.$this->sanitizeForQuery($request->subject).'")'; |
|
136 | 136 | // TODO: Vi bør vel antakelig skille mellom X som emne og X som form/sjanger ? |
137 | 137 | // Men da må frontend si fra hva den ønsker, noe den ikke gjør enda. |
138 | 138 | } |
139 | 139 | if ($request->has('language')) { |
140 | - $query[] = 'language:"' . $this->sanitizeForQuery($request->language) . '"' ; |
|
140 | + $query[] = 'language:"'.$this->sanitizeForQuery($request->language).'"'; |
|
141 | 141 | } |
142 | 142 | if ($request->has('genre')) { |
143 | - $query[] = 'genres.noubomn.prefLabel:"' . $this->sanitizeForQuery($request->genre) . '"'; |
|
143 | + $query[] = 'genres.noubomn.prefLabel:"'.$this->sanitizeForQuery($request->genre).'"'; |
|
144 | 144 | } |
145 | 145 | if ($request->has('real')) { |
146 | 146 | dd('`real` is (very) deprecated, please use `subject` instead.'); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | public function getUsageCount($id, $type) |
179 | 179 | { |
180 | 180 | $this->getFullType($type); |
181 | - $arg = $type . '.' . $id; |
|
181 | + $arg = $type.'.'.$id; |
|
182 | 182 | if (is_null(array_get($this->usage, $arg))) { |
183 | 183 | $this->addToUsageCache($id, $type); |
184 | 184 | } |
@@ -207,11 +207,11 @@ discard block |
||
207 | 207 | ->get(); |
208 | 208 | |
209 | 209 | foreach ($entity_ids as $sid) { |
210 | - array_set($this->usage, $type . '.' . $sid, 0); |
|
210 | + array_set($this->usage, $type.'.'.$sid, 0); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | foreach ($res as $row) { |
214 | - array_set($this->usage, $type . '.' . $row->entity_id, intval($row->doc_count)); |
|
214 | + array_set($this->usage, $type.'.'.$row->entity_id, intval($row->doc_count)); |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | $query = \DB::table('entities') |
222 | 222 | ->select(['entity_id', 'entity_type', \DB::raw('count(document_id) as doc_count')]) |
223 | 223 | ->groupBy('entity_id', 'entity_type'); |
224 | - $query->chunk(5000, function ($rows) use ($typemap) { |
|
224 | + $query->chunk(5000, function($rows) use ($typemap) { |
|
225 | 225 | foreach ($rows as $row) { |
226 | 226 | $type = $typemap[$row->entity_type]; |
227 | - array_set($this->usage, $type . '.' . $row->entity_id, intval($row->doc_count)); |
|
227 | + array_set($this->usage, $type.'.'.$row->entity_id, intval($row->doc_count)); |
|
228 | 228 | } |
229 | 229 | }); |
230 | 230 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | { |
242 | 242 | $payload = $this->basePayload(); |
243 | 243 | if (!is_null($indexVersion)) { |
244 | - $payload['index'] = $this->esIndex . '_v' . $indexVersion; |
|
244 | + $payload['index'] = $this->esIndex.'_v'.$indexVersion; |
|
245 | 245 | } |
246 | 246 | $payload['id'] = $doc->id; |
247 | 247 | |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | try { |
252 | 252 | $this->client->index($payload); |
253 | 253 | } catch (BadRequest400Exception $e) { |
254 | - \Log::error('ElasticSearch returned error: ' . $e->getMessage() . '. Our request: ' . var_export($payload, true)); |
|
255 | - throw new \ErrorException('ElasticSearch failed to index the document ' . $doc->id . '. Please see the log for payload and full error response. Error message: ' . $e->getMessage()); |
|
254 | + \Log::error('ElasticSearch returned error: '.$e->getMessage().'. Our request: '.var_export($payload, true)); |
|
255 | + throw new \ErrorException('ElasticSearch failed to index the document '.$doc->id.'. Please see the log for payload and full error response. Error message: '.$e->getMessage()); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | if (is_null($version)) { |
274 | 274 | $version = $this->getCurrentVersion() + 1; |
275 | 275 | } |
276 | - $indexParams = ['index' => $this->esIndex . '_v' . $version]; |
|
276 | + $indexParams = ['index' => $this->esIndex.'_v'.$version]; |
|
277 | 277 | $indexParams['body']['settings']['analysis']['char_filter']['isbn_filter'] = [ |
278 | 278 | 'type' => 'pattern_replace', |
279 | 279 | 'pattern' => '-', |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | { |
316 | 316 | try { |
317 | 317 | $this->client->indices()->delete([ |
318 | - 'index' => $this->esIndex . '_v' . $version, |
|
318 | + 'index' => $this->esIndex.'_v'.$version, |
|
319 | 319 | ]); |
320 | 320 | } catch (Missing404Exception $e) { |
321 | 321 | # Didn't exist in the beginning, that's ok. |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | public function addAction(&$actions, $action, $version) |
326 | 326 | { |
327 | 327 | if ($version) { |
328 | - $actions[] = [$action => ['index' => $this->esIndex . '_v' . $version, 'alias' => $this->esIndex]]; |
|
328 | + $actions[] = [$action => ['index' => $this->esIndex.'_v'.$version, 'alias' => $this->esIndex]]; |
|
329 | 329 | } |
330 | 330 | } |
331 | 331 | |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | |
343 | 343 | public function versionExists($version) |
344 | 344 | { |
345 | - return $this->client->indices()->exists(['index' => $this->esIndex . '_v' . $version]); |
|
345 | + return $this->client->indices()->exists(['index' => $this->esIndex.'_v'.$version]); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | public function getCurrentVersion() |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $this->comment('Available configurations:'); |
49 | 49 | $config = \Config::get('oaipmh.harvests', null); |
50 | 50 | foreach (array_keys($config) as $key) { |
51 | - $this->comment(' - ' . $key); |
|
51 | + $this->comment(' - '.$key); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | return false; |
61 | 61 | } |
62 | - $harvestConfig = \Config::get('oaipmh.harvests.' . $this->argument('name'), null); |
|
62 | + $harvestConfig = \Config::get('oaipmh.harvests.'.$this->argument('name'), null); |
|
63 | 63 | if (is_null($harvestConfig)) { |
64 | 64 | $this->error('Unknown configuration specified.'); |
65 | 65 | $this->listConfigurations(); |
@@ -108,16 +108,16 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | $harvestName = $this->argument('name'); |
111 | - $harvestConfig = \Config::get('oaipmh.harvests.' . $harvestName, null); |
|
111 | + $harvestConfig = \Config::get('oaipmh.harvests.'.$harvestName, null); |
|
112 | 112 | |
113 | 113 | $this->comment(sprintf('Dispatching new harvest job')); |
114 | 114 | |
115 | 115 | if ($this->option('from-dump')) { |
116 | 116 | $this->comment(' - From local dump'); |
117 | 117 | } else { |
118 | - $this->comment(' - Repo: ' . $harvestConfig['url']); |
|
119 | - $this->comment(' - Schema: ' . $harvestConfig['schema']); |
|
120 | - $this->comment(' - Set: ' . $harvestConfig['set']); |
|
118 | + $this->comment(' - Repo: '.$harvestConfig['url']); |
|
119 | + $this->comment(' - Schema: '.$harvestConfig['schema']); |
|
120 | + $this->comment(' - Set: '.$harvestConfig['set']); |
|
121 | 121 | |
122 | 122 | foreach (['from', 'until', 'resume', 'daily'] as $key) { |
123 | 123 | if (!is_null($this->option($key))) { |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function fromDump() |
90 | 90 | { |
91 | - $files = Storage::disk('local')->files('harvests/' . $this->name); |
|
91 | + $files = Storage::disk('local')->files('harvests/'.$this->name); |
|
92 | 92 | $recordsHarvested = 0; |
93 | 93 | foreach ($files as $filename) { |
94 | 94 | if (!preg_match('/.xml$/', $filename)) { |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | |
112 | 112 | public function fromNetwork() |
113 | 113 | { |
114 | - $dest_path = 'harvests/' . $this->name . '/'; |
|
114 | + $dest_path = 'harvests/'.$this->name.'/'; |
|
115 | 115 | |
116 | 116 | Storage::disk('local')->deleteDir($dest_path); |
117 | 117 | |
118 | - $latest = $dest_path . 'latest.xml'; |
|
118 | + $latest = $dest_path.'latest.xml'; |
|
119 | 119 | |
120 | 120 | $client = new OaiPmhClient($this->url, [ |
121 | 121 | 'schema' => $this->schema, |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | 'sleep-time-on-error' => $this->sleepTimeOnError, |
125 | 125 | ]); |
126 | 126 | |
127 | - $client->on('request.error', function ($msg) { |
|
127 | + $client->on('request.error', function($msg) { |
|
128 | 128 | $this->error($msg); |
129 | 129 | }); |
130 | 130 | |
131 | 131 | // Store each response to disk just in case |
132 | - $client->on('request.complete', function ($verb, $args, $body) use ($latest) { |
|
132 | + $client->on('request.complete', function($verb, $args, $body) use ($latest) { |
|
133 | 133 | Storage::disk('local')->put($latest, $body); |
134 | 134 | }); |
135 | 135 | |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | if ($this->resume != $records->getResumptionToken()) { |
154 | 154 | $this->resume = $records->getResumptionToken(); |
155 | 155 | if (is_null($this->resume)) { |
156 | - Storage::disk('local')->delete($dest_path . '/resumption_token'); |
|
156 | + Storage::disk('local')->delete($dest_path.'/resumption_token'); |
|
157 | 157 | } else { |
158 | - Storage::disk('local')->put($dest_path . '/resumption_token', $this->resume); |
|
158 | + Storage::disk('local')->put($dest_path.'/resumption_token', $this->resume); |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | } catch (BadRequestError $e) { |
189 | 189 | $this->error($e->getMessage()); |
190 | 190 | $this->error($e->getCode()); |
191 | - $this->error('Bad request. Attempt ' . $attempt . ' of 100. Sleeping 10 secs.'); |
|
191 | + $this->error('Bad request. Attempt '.$attempt.' of 100. Sleeping 10 secs.'); |
|
192 | 192 | if ($attempt > 100) { |
193 | 193 | throw $e; |
194 | 194 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function handle() |
211 | 211 | { |
212 | - Log::info('[OaiPmhHarvest] Starting job. Requesting records from ' . ($this->start ?: '(no limit)') . ' until ' . ($this->until ?: '(no limit)') . '.'); |
|
212 | + Log::info('[OaiPmhHarvest] Starting job. Requesting records from '.($this->start ?: '(no limit)').' until '.($this->until ?: '(no limit)').'.'); |
|
213 | 213 | |
214 | 214 | // For timing |
215 | 215 | $this->startTime = $this->batchTime = microtime(true) - 1; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | $recordsHarvested = $this->fromNetwork(); |
228 | 228 | } |
229 | 229 | |
230 | - Log::info('[OaiPmhHarvest] Harvest complete, got ' . $recordsHarvested . ' records.'); |
|
230 | + Log::info('[OaiPmhHarvest] Harvest complete, got '.$recordsHarvested.' records.'); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | $msg = vsprintf($msg, $args); |
41 | 41 | $docLink = sprintf('<http://colligator.biblionaut.net/api/documents/%s|#%s> ', $doc->id, $doc->id); |
42 | 42 | \Slack::attach([ |
43 | - 'fallback' => '#' . $doc->id . ' ' . $msg, |
|
44 | - 'text' => $docLink . $msg, |
|
43 | + 'fallback' => '#'.$doc->id.' '.$msg, |
|
44 | + 'text' => $docLink.$msg, |
|
45 | 45 | 'color' => $level, |
46 | 46 | ])->send(); |
47 | 47 | } |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function updateDocument(Document $doc, $url) |
67 | 67 | { |
68 | - \Log::debug('[DescriptionScraper] Looking for decription for ' . $doc->id . ' at ' . $url); |
|
68 | + \Log::debug('[DescriptionScraper] Looking for decription for '.$doc->id.' at '.$url); |
|
69 | 69 | |
70 | 70 | if (preg_match('/(damm.no)/', $url)) { |
71 | - \Log::debug('[DescriptionScraper] Ignoring URL: ' . $url); |
|
71 | + \Log::debug('[DescriptionScraper] Ignoring URL: '.$url); |
|
72 | 72 | |
73 | 73 | return; |
74 | 74 | } |
@@ -76,18 +76,18 @@ discard block |
||
76 | 76 | try { |
77 | 77 | $result = $this->scrape($url); |
78 | 78 | } catch (TransferException $e) { |
79 | - \Log::error('[DescriptionScraper] Transfer failed: ' . $e->getMessage()); |
|
79 | + \Log::error('[DescriptionScraper] Transfer failed: '.$e->getMessage()); |
|
80 | 80 | $this->notify('*DescriptionScraper* failed to fetch: %s', $doc, [$url]); |
81 | 81 | |
82 | 82 | return; |
83 | 83 | } catch (Scrapers\ScrapeException $e) { |
84 | - \Log::error('[DescriptionScraper] Scraping of ' . $url . ' failed: ' . $e->getMessage()); |
|
84 | + \Log::error('[DescriptionScraper] Scraping of '.$url.' failed: '.$e->getMessage()); |
|
85 | 85 | $this->notify('*DescriptionScraper* / %s failed to find a text at: %s', $doc, [$e->getMessage(), $url]); |
86 | 86 | |
87 | 87 | return; |
88 | 88 | } |
89 | 89 | if (is_null($result)) { |
90 | - \Log::error('Encountered URL not recognized by any scraper: ' . $url); |
|
90 | + \Log::error('Encountered URL not recognized by any scraper: '.$url); |
|
91 | 91 | $this->notify('*DescriptionScraper* encountered URL not recognized by any sraper: %s', $doc, [$url]); |
92 | 92 | |
93 | 93 | return; |