-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes bug date of Lychee + prepare work for date search
- Loading branch information
Showing
4 changed files
with
176 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
database/migrations/2018_12_30_161607_change_takestamp_format.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
database/migrations/2018_12_30_165003_change_max_min_takestamp_format.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
} | ||
} |