Pony.fm/app/Console/Commands/MigrateEncryption.php
2016-11-21 00:42:43 +00:00

58 lines
1.3 KiB
PHP

<?php
namespace Poniverse\Ponyfm\Console\Commands;
use DB;
use Illuminate\Console\Command;
use Laravel\LegacyEncrypter\McryptEncrypter;
class MigrateEncryption extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrate-encryption';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Migrates from mcrypt to openssl. Needs key and mcryptKey set in config/app.php';
/**
* Create a new command instance.
*
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$key = $this->laravel['config']['app.mcryptKey'];
$cipher = $this->laravel['config']['app.mcryptCipher'];
$legacy = new McryptEncrypter($key, $cipher);
$caches = DB::select('SELECT * FROM cache');
foreach ($caches as $cache) {
$newValue = encrypt(
$legacy->decrypt($cache->value)
);
DB::update('UPDATE cache SET value = ? WHERE key = ?', [$cache->key, $newValue]);
$this->info("Updated {$cache->key}");
}
}
}