Try to prevent insertion of duplicated Xref data

This commit is contained in:
DariusIII
2019-01-07 17:31:54 +01:00
parent bd6fae35ec
commit 048e181162
2 changed files with 17 additions and 1 deletions
+16 -1
View File
@@ -2,6 +2,7 @@
namespace Blacklight;
use App\Models\Collection;
use App\Models\Group;
use App\Models\Settings;
use Illuminate\Support\Carbon;
@@ -787,7 +788,21 @@ class Binaries
// Get the current unixtime from PHP.
$now = now()->timestamp;
$xref = sprintf('xref = CONCAT(xref, "\\n"%s ),', escapeString(substr($this->header['Xref'], 2, 255)));
$collHashXref = Collection::query()->where('collectionhash', $this->header['CollectionKey'])->select(['xref'])->first();
$xrefs = [];
if ($collHashXref !== null) {
$collXrefs = explode(' ', $collHashXref->value('xref'));
foreach ($collXrefs as $collXref) {
if (preg_match('/(^alt\.binaries\.\w+)/', $collXref, $match)) {
$xrefs[] = $match[0];
}
}
}
preg_match('/(alt\.binaries\.\w+)/', $this->header['Xref'], $match2);
$xref = ! empty($xrefs) && ! \in_array($match2[0], $xrefs, false) ? sprintf('xref = CONCAT(xref, "\\n"%s ),', escapeString(substr($this->header['Xref'], 2, 255))) : '';
$date = $this->header['Date'] > $now ? $now : $this->header['Date'];
$unixtime = is_numeric($this->header['Date']) ? $date : $now;
+1
View File
@@ -1,4 +1,5 @@
2019-01-07 DariusIII
* Chg: Try to prevent insertion of duplicated Xref data
* Chg: More File facade usage for files manipulation
* Chg: Remove MenuTableSeeder as the model and table do not exist anymore
* Chg: Update PreDb class and predb_import_daily_batch script