Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiltri committed Nov 19, 2024
2 parents 77f1986 + ba2ef76 commit 2889b55
Show file tree
Hide file tree
Showing 120 changed files with 4,126 additions and 2,044 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ DB_DATABASE='homestead'
DB_USERNAME='homestead'
DB_PASSWORD='secret'

# Comma-delimited list
HIDE_FROM_TOURS=

TOURS_DB_CONNECTION='mysql'
TOURS_DB_HOST='127.0.0.1'
TOURS_DB_PORT=3306
Expand Down
53 changes: 53 additions & 0 deletions app/Console/Commands/MigrateOSCIPublication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class MigrateOSCIPublication extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrate:osci-publication';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Migrate all OSCI publications from a migration file to website DigitalPublications';

protected $publications = [
'albright',
'americansilver',
'caillebotte',
'digitalwhistler',
'ensor',
'gauguin',
'manet',
'matisse',
'modernseries',
'modernseries2',
'monet',
'pissarro',
'renoir',
'romanart',
'whistler_linkedvisions',
'whistlerart',
];

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
foreach ($this->publications as $pub) {
$this->call('migrate:osci-publication-one', ['id' => $pub]);
}
}
}
53 changes: 53 additions & 0 deletions app/Console/Commands/MigrateOSCIPublicationMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class MigrateOSCIPublicationMedia extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrate:osci-media';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Migrate all OSCI publications\' IIP and 360º media from OSCI servers to S3';

protected $publications = [
'albright',
'americansilver',
'caillebotte',
'digitalwhistler',
'ensor',
'gauguin',
'manet',
'matisse',
'modernseries',
'modernseries2',
'monet',
'pissarro',
'renoir',
'romanart',
'whistler_linkedvisions',
'whistlerart',
];

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
foreach ($this->publications as $pub) {
$this->call('migrate:osci-media-one', ['id' => $pub]);
}
}
}
98 changes: 98 additions & 0 deletions app/Console/Commands/MigrateOSCIPublicationMediaOne.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace App\Console\Commands;

use Imagick;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;

$PTIF_LAYER_MAX = 10000;

class MigrateOSCIPublicationMediaOne extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrate:osci-media-one {id : Publication ID}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Migrate an OSCI publications\' IIP and 360º media from OSCI servers to S3';

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$pubId = $this->argument('id');
$this->comment('Starting ' . $pubId . '...');

# TODO: Query 360s too
$assetsQuery = <<<EOT
SELECT DISTINCT json_extract(layers.value,'$._image_ident') AS image_ident
FROM figure_layers,
json_each(figure_layers.data,'$.layers') AS layers
WHERE json_extract(layers.value,'$._type')='iip'
AND figure_layers.package=:pubId
ORDER BY json_extract(layers.value,'$._height') ASC
EOT;

$assets = DB::connection('osci_migration')->select($assetsQuery, ['pubId' => $pubId]);

foreach ($assets as $asset) {
// TODO: Check the asset type and handle 360 spins differently
$key = trim($asset->image_ident, '/');
$asset_key = preg_replace('/^\/?osci\//', '', $asset->image_ident);
$jpg_key = preg_replace('/\.ptif$/', '.jpg', $key);

if (!Storage::disk('osci_s3')->fileExists($asset_key)) {
$this->info("OSCI_S3_BUCKET did not contain {$asset_key}!");
continue;
}

if (Storage::disk('osci_s3')->fileExists($jpg_key)) {
$this->info("OSCI_S3_BUCKET already contains {$jpg_key}, skipping this asset");
continue;
}

$this->info("Compressing {$asset_key}");

$content = Storage::disk('osci_s3')->get($asset_key);

$image = new Imagick();
$image->readImageBlob($content);

// Iterate zoom layers to find a 10k-pixels-a-side page geometry
while ($image->hasPreviousImage()) {
$size = $image->getImagePage();

if ($size['height'] > 10000 && $size['width'] > 10000) {
$image->nextImage();
break;
}
$image->previousImage();
}

$image->setImageFormat('jpeg');
$compressed = $image->getImageBlob();

$res = Storage::disk('osci_s3')->put($jpg_key, $compressed);

if (!$res) {
$this->info("There was an error uploading the compressed file to {$jpg_key}");
continue;
}

echo "Uploaded {$jpg_key}\n";
}
$this->comment('...' . $pubId . ' done!');
}
}
Loading

0 comments on commit 2889b55

Please sign in to comment.