Skip to content

Commit

Permalink
Display for media with same id but various trees fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
UksusoFF committed Jun 22, 2020
1 parent 1951afe commit 4c2ccb3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
37 changes: 30 additions & 7 deletions src/Helpers/DatabaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,37 @@ public function getIndividualsDataByTreeAndPids(string $tree, array $pids): Coll
->get();
}

public function getMediaMap(string $media, int $order): ?string
{
public function getMediaMap(
int $tree,
string $media,
int $order
): ?string {
return DB::table('media_faces')
->where('f_m_id', '=', $media)
->where('f_m_order', '=', $order)
->where('f_m_tree', '=', $tree)
->value('f_coordinates');
}

public function setMediaMap(string $media, int $order, ?string $filename = null, ?string $map = null): ?int
{
public function setMediaMap(
int $tree,
string $media,
int $order,
?string $filename = null,
?string $map = null
): ?int {
if ($map === null) {
return DB::table('media_faces')
->where('f_m_id', '=', $media)
->where('f_m_order', '=', $order)
->where('f_m_tree', '=', $tree)
->delete();
}

DB::table('media_faces')->updateOrInsert([
'f_m_id' => $media,
'f_m_order' => $order,
'f_m_tree' => $tree,
], [
'f_coordinates' => $map,
'f_m_filename' => $filename,
Expand All @@ -74,7 +85,11 @@ public function getMediaList(?string $media, ?string $person, ?string $search, i

return [
$query
->leftJoin('media', 'f_m_id', '=', 'm_id')
->leftJoin('media', function (JoinClause $join) {
$join
->on('f_m_id', '=', 'm_id')
->on('f_m_tree', '=', 'm_file');
})
->skip($start)
->take($length)
->get([
Expand All @@ -93,7 +108,11 @@ public function missedNotesRepair(): int
$count = 0;

DB::table('media_faces')
->leftJoin('media', 'f_m_id', '=', 'm_id')
->leftJoin('media', function (JoinClause $join) {
$join
->on('f_m_id', '=', 'm_id')
->on('f_m_tree', '=', 'm_file');
})
->whereNull('media.m_id')
->chunkById(20, function($chunks) use (&$count) {
foreach ($chunks as $chunk) {
Expand All @@ -117,7 +136,11 @@ public function missedNotesRepair(): int
public function missedNotesDestroy(): int
{
return DB::table('media_faces')
->leftJoin('media', 'f_m_id', '=', 'm_id')
->leftJoin('media', function (JoinClause $join) {
$join
->on('f_m_id', '=', 'm_id')
->on('f_m_tree', '=', 'm_file');
})
->whereNull('media.m_id')
->delete();
}
Expand Down
7 changes: 6 additions & 1 deletion src/Http/Controllers/DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ private function getMediaMap(Media $media, string $fact): array
throw new HttpNotFoundException();
}

if (($map = $this->module->query->getMediaMap($media->xref(), $order)) !== null) {
if (($map = $this->module->query->getMediaMap(
$media->tree()->id(),
$media->xref(),
$order
)) !== null) {
return json_decode($map, true);
}

Expand All @@ -276,6 +280,7 @@ private function setMediaMap(Media $media, string $fact, array $map = []): void
}

$this->module->query->setMediaMap(
$media->tree()->id(),
$media->xref(),
$order,
$file->filename(),
Expand Down
30 changes: 30 additions & 0 deletions src/Migrations/Migration5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace UksusoFF\WebtreesModules\Faces\Migrations;

use Fisharebest\Webtrees\Schema\MigrationInterface;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Schema\Blueprint;

/**
* Migrate data from oldest versions.
*/
class Migration5 implements MigrationInterface
{
public function upgrade(): void
{
DB::schema()->table('media_faces', static function(Blueprint $table): void {
$table->unsignedInteger('f_m_tree')->nullable();
});

DB::table('media_faces')
->leftJoin('media', 'f_m_id', '=', 'm_id')
->update([
'f_m_tree' => DB::raw('m_file'),
]);

DB::schema()->table('media_faces', static function(Blueprint $table): void {
$table->unsignedInteger('f_m_tree')->nullable(false)->change();
});
}
}
2 changes: 1 addition & 1 deletion src/Modules/FacesModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FacesModule extends AbstractModule implements ModuleCustomInterface, Modul
use ModuleGlobalTrait;
use ModuleConfigTrait;

public const SCHEMA_VERSION = '5';
public const SCHEMA_VERSION = '6';

public const CUSTOM_VERSION = '2.6.4';

Expand Down

0 comments on commit 4c2ccb3

Please sign in to comment.