Skip to content

Commit

Permalink
fixes bug date of Lychee + prepare work for date search
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Dec 30, 2018
1 parent 6f18264 commit 5d52c10
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 6 deletions.
10 changes: 8 additions & 2 deletions app/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

class Album extends Model
{

protected $dates = ['created_at', 'updated_at', 'min_takestamp', 'max_takestamp'];


public function photos()
{
return $this->hasMany('App\Photo','album_id','id');
Expand Down Expand Up @@ -42,8 +46,10 @@ public function prepareData() {

// Parse date
$album['sysdate'] = $this->created_at->format('F Y');
$album['min_takestamp'] = $this->min_takestamp == 0 ? '' : strftime('%B %Y', $this->min_takestamp);
$album['max_takestamp'] = $this->max_takestamp == 0 ? '' : strftime('%B %Y', $this->max_takestamp);
$album['min_takestamp'] = $this->min_takestamp == null ? '' : $this->min_takestamp->format('M Y');
// strftime('%B %Y', $this->min_takestamp);
$album['max_takestamp'] = $this->max_takestamp == null ? '' : $this->max_takestamp->format('M Y');
//strftime('%B %Y', $this->max_takestamp);

// Parse password
$album['password'] = ($this->password == '' ? '0' : '1');
Expand Down
25 changes: 21 additions & 4 deletions app/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

class Photo extends Model
{

protected $dates = ['created_at', 'updated_at', 'takestamp'];

public function album()
{
return $this->belongsTo('App\Album','album_id','id');
Expand Down Expand Up @@ -114,12 +117,12 @@ public function prepareData() {
$photo['url'] = Config::get('defines.urls.LYCHEE_URL_UPLOADS_BIG') . $this->url;

// Use takestamp as sysdate when possible
if (isset($this->takestamp) && $this->takestamp > 0) {
if (isset($this->takestamp) && $this->takestamp != null) {

// Use takestamp
$photo['cameraDate'] = '1';
$photo['sysdate'] = $this->created_at->format('d F Y');
$photo['takedate'] = strftime('%d %B %Y at %H:%M', $this->takestamp);
$photo['takedate'] = $this->takestamp->format('d F Y \a\t H:i');

} else {

Expand Down Expand Up @@ -186,7 +189,7 @@ static public function getInformations(string $url) {
$return['model'] = '';
$return['shutter'] = '';
$return['focal'] = '';
$return['takestamp'] = 0;
$return['takestamp'] = null;
$return['lens'] = '';
$return['tags'] = '';
$return['position'] = '';
Expand Down Expand Up @@ -268,7 +271,21 @@ static public function getInformations(string $url) {
}

// Takestamp
if (!empty($exif['DateTimeOriginal'])) $return['takestamp'] = strtotime($exif['DateTimeOriginal']);
if (!empty($exif['DateTimeOriginal']))
{
if ($exif['DateTimeOriginal'] == '0000:00:00 00:00:00')
{
$return['takestamp'] = null;
}
else if(strtotime($exif['DateTimeOriginal']) == 0)
{
$return['takestamp'] = null;
}
else
{
$return['takestamp'] = date("Y-m-d H:i:s", strtotime($exif['DateTimeOriginal']));
}
}

if (!empty($exif['LensInfo'])) $return['lens'] = trim($exif['LensInfo']);
// Lens field from Lightroom
Expand Down
70 changes: 70 additions & 0 deletions database/migrations/2018_12_30_161607_change_takestamp_format.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

use App\Photo;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class ChangeTakestampFormat extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// create temporary field.
Schema::table('photos', function (Blueprint $table) {
$table->timestamp('takestamp_temp')->nullable()->after('takestamp');
});

// copy
$photos = Photo::all();
foreach ($photos as $photo) {
$photo->takestamp_temp = ($photo->takestamp == 0 || $photo->takestamp == null) ? null : date("Y-m-d H:i:s", $photo->takestamp);
$photo->save();
}

// delete
Schema::table('photos', function (Blueprint $table) {
$table->dropColumn('takestamp');
});

// rename
Schema::table('photos', function (Blueprint $table) {
$table->renameColumn('takestamp_temp', 'takestamp');
});

}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// rename
Schema::table('photos', function (Blueprint $table) {
$table->renameColumn('takestamp', 'takestamp_temp');
});

// create
Schema::table('photos', function (Blueprint $table) {
$table->integer('takestamp')->nullable()->after('takestamp_temp');
});

// copy
$photos = Photo::all();
foreach ($photos as $photo) {
$photo->takestamp = ($photo->takestamp_temp == null) ? 0 : strtotime($photo->takestamp_temp);
$photo->save();
}

// delete
Schema::table('photos', function (Blueprint $table) {
$table->dropColumn('takestamp_temp');
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

use App\Album;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class ChangeMaxMinTakestampFormat extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// create temporary field.
Schema::table('albums', function (Blueprint $table) {
$table->timestamp('min_takestamp_temp')->nullable()->after('min_takestamp');
$table->timestamp('max_takestamp_temp')->nullable()->after('max_takestamp');
});

// copy
$photos = Album::all();
foreach ($photos as $album) {
$album->min_takestamp_temp = ($album->min_takestamp == 0 || $album->min_takestamp == null) ? null : date("Y-m-d H:i:s", $album->min_takestamp);
$album->max_takestamp_temp = ($album->max_takestamp == 0 || $album->max_takestamp == null) ? null : date("Y-m-d H:i:s", $album->max_takestamp);
$album->save();
}

// delete
Schema::table('albums', function (Blueprint $table) {
$table->dropColumn('min_takestamp');
$table->dropColumn('max_takestamp');
});

// rename
Schema::table('albums', function (Blueprint $table) {
$table->renameColumn('min_takestamp_temp', 'min_takestamp');
$table->renameColumn('max_takestamp_temp', 'max_takestamp');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// rename
Schema::table('albums', function (Blueprint $table) {
$table->renameColumn('min_takestamp', 'min_takestamp_temp');
$table->renameColumn('max_takestamp', 'max_takestamp_temp');
});

// create
Schema::table('albums', function (Blueprint $table) {
$table->integer('min_takestamp')->nullable()->after('min_takestamp_temp');
$table->integer('max_takestamp')->nullable()->after('max_takestamp_temp');
});

// copy
$albums = Album::all();
foreach ($albums as $album) {
$album->min_takestamp = ($album->min_takestamp_temp == null) ? 0 : strtotime($album->min_takestamp_temp);
$album->max_takestamp = ($album->max_takestamp_temp == null) ? 0 : strtotime($album->max_takestamp_temp);
$album->save();
}

// delete
Schema::table('albums', function (Blueprint $table) {
$table->dropColumn('min_takestamp_temp');
$table->dropColumn('max_takestamp_temp');
});
}
}

0 comments on commit 5d52c10

Please sign in to comment.