Skip to content

Commit

Permalink
Improve backup & increase sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbrendel committed Jul 1, 2024
1 parent d4b68d7 commit 105ec5d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
4 changes: 2 additions & 2 deletions 99-php.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
upload_max_filesize = 15M
post_max_size = 15M
upload_max_filesize = 5000M
post_max_size = 5500M
22 changes: 22 additions & 0 deletions app/modules/BackupModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static function start($options = [])

if ((isset($options['plants'])) && ($options['plants'])) {
$cleanup_files[] = static::backupPlants($zip);
$cleanup_files[] = static::backupPlantLog($zip);
}

if ((isset($options['gallery'])) && ($options['gallery'])) {
Expand Down Expand Up @@ -113,6 +114,27 @@ private static function backupPlants(ZipArchive $zip)
}
}

/**
* @param $zip
* @return string
* @throws \Exception
*/
private static function backupPlantLog(ZipArchive $zip)
{
try {
$plantlog = PlantLogModel::raw('SELECT * FROM `plantlog`');

$zip->addEmptyDir('plantlog');

file_put_contents(public_path() . '/backup/_plantlog.json', json_encode($plantlog->asArray()));
$zip->addFile(public_path() . '/backup/_plantlog.json', 'plantlog/data.json');

return public_path() . '/backup/_plantlog.json';
} catch (\Exception $e) {
throw $e;
}
}

/**
* @param $zip
* @return string
Expand Down
34 changes: 31 additions & 3 deletions app/modules/ImportModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static function start($options = [])

if ((isset($options['plants'])) && ($options['plants'])) {
static::importPlants(public_path() . '/backup/' . $import_file . '/plants');
static::importPlantLog(public_path() . '/backup/' . $import_file . '/plantlog');
}

if ((isset($options['gallery'])) && ($options['gallery'])) {
Expand Down Expand Up @@ -74,7 +75,8 @@ public static function importLocations($path)
$locations = json_decode(file_get_contents($path . '/data.json'));
if ($locations) {
foreach ($locations as $location) {
LocationsModel::raw('INSERT INTO `' . LocationsModel::tableName() . '` (name, icon, active, created_at) VALUES(?, ?, ?, ?)', [
LocationsModel::raw('INSERT INTO `' . LocationsModel::tableName() . '` (id, name, icon, active, created_at) VALUES(?, ?, ?, ?, ?)', [
$location->id,
$location->name,
$location->icon,
$location->active,
Expand All @@ -98,7 +100,8 @@ public static function importPlants($path)
$plants = json_decode(file_get_contents($path . '/data.json'));
if ($plants) {
foreach ($plants as $plant) {
PlantsModel::raw('INSERT INTO `' . PlantsModel::tableName() . '` (name, scientific_name, knowledge_link, tags, location, photo, last_watered, last_repotted, perennial, cutting_month, date_of_purchase, humidity, light_level, health_state, notes, history, history_date, last_edited_user, last_edited_date, created_at) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
PlantsModel::raw('INSERT INTO `' . PlantsModel::tableName() . '` (id, name, scientific_name, knowledge_link, tags, location, photo, last_watered, last_repotted, perennial, cutting_month, date_of_purchase, humidity, light_level, health_state, notes, history, history_date, last_edited_user, last_edited_date, created_at) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
$plant->id,
$plant->name,
$plant->scientific_name,
$plant->knowledge_link,
Expand Down Expand Up @@ -131,6 +134,30 @@ public static function importPlants($path)
}
}

/**
* @param $path
* @return void
* @throws \Exception
*/
public static function importPlantLog($path)
{
try {
$plantlog_entries = json_decode(file_get_contents($path . '/data.json'));
if ($plantlog_entries) {
foreach ($plantlog_entries as $plantlog_entry) {
PlantLogModel::raw('INSERT INTO `' . PlantLogModel::tableName() . '` (plant, content, updated_at, created_at) VALUES(?, ?, ?, ?)', [
$plantlog_entry->plant,
$plantlog_entry->content,
$plantlog_entry->updated_at,
$plantlog_entry->created_at
]);
}
}
} catch (\Exception $e) {
throw $e;
}
}

/**
* @param $path
* @return void
Expand Down Expand Up @@ -201,7 +228,8 @@ public static function importInvGroups($path)
$invgroup_items = json_decode(file_get_contents($path . '/data.json'));
if ($invgroup_items) {
foreach ($invgroup_items as $invgroup_item) {
InvGroupModel::raw('INSERT INTO `' . InvGroupModel::tableName() . '` (token, label, created_at) VALUES(?, ?, ?)', [
InvGroupModel::raw('INSERT INTO `' . InvGroupModel::tableName() . '` (id, token, label, created_at) VALUES(?, ?, ?, ?)', [
$invgroup_item->id,
$invgroup_item->token,
$invgroup_item->label,
$invgroup_item->created_at
Expand Down

0 comments on commit 105ec5d

Please sign in to comment.