|
3 | 3 | namespace NotFound\Framework\Models\Indexes;
|
4 | 4 |
|
5 | 5 | use Illuminate\Support\Facades\Mail;
|
6 |
| -use Illuminate\Support\Facades\Storage; |
7 | 6 | use NotFound\Framework\Mail\Indexer\FileIndexError;
|
8 | 7 | use NotFound\Framework\Mail\Indexer\QueryError;
|
9 | 8 | use NotFound\Framework\Models\BaseModel;
|
@@ -131,14 +130,14 @@ public function testSolrConnection()
|
131 | 130 | return false;
|
132 | 131 | }
|
133 | 132 |
|
134 |
| - public function upsertItem(SearchItem $indexItem, int $siteId = 1): bool |
| 133 | + public function upsertItem(SearchItem $indexItem, int $siteId = 1, ?string $domain = null): bool |
135 | 134 | {
|
136 | 135 | $curl = $this->solrHandler();
|
137 | 136 | $doc = [
|
138 | 137 | sprintf('title_%s', $indexItem->language()) => $indexItem->title(),
|
139 | 138 | sprintf('content_%s', $indexItem->language()) => html_entity_decode(trim(preg_replace('/\s+/', ' ', preg_replace('#<[^>]+>#', ' ', $indexItem->content())))),
|
140 | 139 | 'type' => $indexItem->type(),
|
141 |
| - 'url' => $this->siteUrl($indexItem->url(), $siteId), |
| 140 | + 'url' => $this->siteUrl($indexItem->url(), $domain), |
142 | 141 | 'priority' => $indexItem->priority(),
|
143 | 142 | 'site' => $siteId,
|
144 | 143 | 'language' => $indexItem->language(),
|
@@ -197,19 +196,20 @@ public function removeItem($url)
|
197 | 196 | return false;
|
198 | 197 | }
|
199 | 198 |
|
200 |
| - public function upsertFile(SearchItem $indexItem, int $siteId = 1): string |
| 199 | + public function upsertFile(SearchItem $indexItem, int $siteId = 1, ?string $domain = null): string |
201 | 200 | {
|
202 | 201 |
|
203 | 202 | // find out of document exists
|
204 | 203 | $result = 0;
|
205 |
| - $file = Storage::disk('private')->path($indexItem->file()); |
| 204 | + // TODO: check if path is within allowed path |
| 205 | + $file = $indexItem->file(); |
206 | 206 |
|
207 | 207 | if (file_exists($file)) {
|
208 | 208 | $curl = $this->solrHandler();
|
209 | 209 | $endpoint = sprintf(
|
210 | 210 | '%s/update/extract?literal.url=%s&literal.title_%s=%s&literal.type=%s&literal.site=%s&literal.language=%d&literal.solr_date=%s&uprefix=ignored_&fmap.content=content_%s&commit=true',
|
211 | 211 | $this->getSolrBaseUrl(),
|
212 |
| - urlencode($this->siteUrl($indexItem->url(), $siteId)), |
| 212 | + urlencode($this->siteUrl($indexItem->url(), $domain)), |
213 | 213 | $indexItem->language(),
|
214 | 214 | urlencode($indexItem->title()),
|
215 | 215 | $indexItem->type(),
|
@@ -257,6 +257,7 @@ public function upsertFile(SearchItem $indexItem, int $siteId = 1): string
|
257 | 257 | }
|
258 | 258 | } else {
|
259 | 259 | $this->mailFileError($indexItem->title(), $indexItem->url(), 'file bestaat niet');
|
| 260 | + printf("\nFile not found: %s", $file); |
260 | 261 |
|
261 | 262 | return 'fileNotFound';
|
262 | 263 | }
|
@@ -441,8 +442,12 @@ public function checkConnection(): bool
|
441 | 442 | return false;
|
442 | 443 | }
|
443 | 444 |
|
444 |
| - public function siteUrl($url, $siteId): string |
| 445 | + public function siteUrl($url, ?string $domain): string |
445 | 446 | {
|
446 |
| - return sprintf('{{%d}}%s', $siteId, $url); |
| 447 | + if ($domain) { |
| 448 | + return sprintf('%s/%s', rtrim($domain, '/'), ltrim($url, '/')); |
| 449 | + } |
| 450 | + |
| 451 | + return $url; |
447 | 452 | }
|
448 | 453 | }
|
0 commit comments