Files
firefly-iii/app/Export/ConfigurationFile.php

67 lines
1.6 KiB
PHP
Raw Normal View History

2016-02-04 17:16:16 +01:00
<?php
/**
* ConfigurationFile.php
2016-04-01 16:44:46 +02:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
2016-02-04 17:16:16 +01:00
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
2016-02-04 17:16:16 +01:00
namespace FireflyIII\Export;
2016-04-26 12:39:29 +02:00
use FireflyIII\Export\Entry\Entry;
2016-02-04 17:16:16 +01:00
use FireflyIII\Models\ExportJob;
2016-02-23 07:07:14 +01:00
use Storage;
2016-02-04 17:16:16 +01:00
/**
* Class ConfigurationFile
*
* @package FireflyIII\Export
*/
class ConfigurationFile
{
2016-02-23 07:07:14 +01:00
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
private $exportDisk;
2016-02-04 17:16:16 +01:00
/** @var ExportJob */
private $job;
2016-02-05 15:41:40 +01:00
/**
* ConfigurationFile constructor.
*
* @param ExportJob $job
*/
2016-02-04 17:16:16 +01:00
public function __construct(ExportJob $job)
{
2016-02-23 07:07:14 +01:00
$this->job = $job;
$this->exportDisk = Storage::disk('export');
2016-02-04 17:16:16 +01:00
}
/**
2016-04-06 16:37:28 +02:00
* @return string
2016-02-04 17:16:16 +01:00
*/
2016-04-06 16:37:28 +02:00
public function make(): string
2016-02-04 17:16:16 +01:00
{
2016-04-26 20:49:22 +02:00
$fields = array_keys(Entry::getFieldsAndTypes());
$types = Entry::getFieldsAndTypes();
2016-02-04 17:16:16 +01:00
$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 07:07:14 +01:00
$file = $this->job->key . '-configuration.json';
$this->exportDisk->put($file, json_encode($configuration, JSON_PRETTY_PRINT));
2016-02-04 17:16:16 +01:00
return $file;
}
2016-02-10 16:01:18 +01:00
}