firefly-iii/app/Console/Commands/EncryptFile.php

71 lines
1.9 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
/**
* EncryptFile.php
2017-10-21 01:40:00 -05:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 01:40:00 -05:00
* This file is part of Firefly III.
*
2017-10-21 01:40:00 -05:00
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2017-12-17 07:41:58 -06:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Console\Commands;
2018-03-30 12:41:16 -05:00
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Services\Internal\File\EncryptService;
use Illuminate\Console\Command;
/**
2017-11-15 05:25:49 -06:00
* Class EncryptFile.
*/
class EncryptFile extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Encrypts a file and places it in the storage/upload directory.';
/**
* The name and signature of the console command.
*
* @var string
*/
2017-01-14 10:24:30 -06:00
protected $signature = 'firefly:encrypt-file {file} {key}';
/**
* Execute the console command.
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
2018-03-30 12:41:16 -05:00
public function handle(): int
{
2018-03-30 12:41:16 -05:00
$code = 0;
$file = (string)$this->argument('file');
$key = (string)$this->argument('key');
/** @var EncryptService $service */
$service = app(EncryptService::class);
2018-03-30 12:41:16 -05:00
try {
$service->encrypt($file, $key);
} catch (FireflyException $e) {
$this->error($e->getMessage());
$code = 1;
}
2018-03-30 12:41:16 -05:00
return $code;
}
}