firefly-iii/app/Export/ConfigurationFile.php

68 lines
1.7 KiB
PHP
Raw Normal View History

2016-02-04 10:16:16 -06:00
<?php
2016-02-05 05:08:25 -06:00
declare(strict_types = 1);
2016-02-04 10:16:16 -06:00
/**
* ConfigurationFile.php
2016-04-01 09:44:46 -05:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
2016-02-04 10:16:16 -06:00
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Export;
use FireflyIII\Models\ExportJob;
use Log;
2016-02-23 00:07:14 -06:00
use Storage;
2016-02-04 10:16:16 -06:00
/**
* Class ConfigurationFile
*
* @package FireflyIII\Export
*/
class ConfigurationFile
{
2016-02-23 00:07:14 -06:00
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
private $exportDisk;
2016-02-04 10:16:16 -06:00
/** @var ExportJob */
private $job;
2016-02-05 08:41:40 -06:00
/**
* ConfigurationFile constructor.
*
* @param ExportJob $job
*/
2016-02-04 10:16:16 -06:00
public function __construct(ExportJob $job)
{
2016-02-23 00:07:14 -06:00
$this->job = $job;
$this->exportDisk = Storage::disk('export');
2016-02-04 10:16:16 -06:00
}
/**
* @return bool
*/
public function make()
{
$fields = array_keys(get_class_vars(Entry::class));
$types = Entry::getTypes();
$configuration = [
'date-format' => 'Y-m-d', // unfortunately, this is hard-coded.
'has-headers' => true,
'map' => [], // we could build a map if necessary for easy re-import.
'roles' => [],
'mapped' => [],
'specifix' => [],
];
foreach ($fields as $field) {
$configuration['roles'][] = $types[$field];
}
2016-02-23 00:07:14 -06:00
$file = $this->job->key . '-configuration.json';
Log::debug('Created JSON config file.');
Log::debug('Will put "' . $file . '" in the ZIP file.');
2016-02-23 00:07:14 -06:00
$this->exportDisk->put($file, json_encode($configuration, JSON_PRETTY_PRINT));
2016-02-04 10:16:16 -06:00
return $file;
}
2016-02-10 09:01:18 -06:00
}