2014-06-30 00:26:38 -05:00
|
|
|
<?php
|
2014-06-30 03:47:14 -05:00
|
|
|
|
2014-07-04 00:22:16 -05:00
|
|
|
use Firefly\Helper\Migration\MigrationHelperInterface as MHI;
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* Class MigrationController
|
|
|
|
*/
|
2014-06-30 03:47:14 -05:00
|
|
|
class MigrationController extends BaseController
|
|
|
|
{
|
2014-07-15 15:16:29 -05:00
|
|
|
protected $_migration;
|
2014-07-04 00:22:16 -05:00
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @param MHI $migration
|
|
|
|
*/
|
2014-07-04 00:22:16 -05:00
|
|
|
public function __construct(MHI $migration)
|
|
|
|
{
|
2014-07-15 15:16:29 -05:00
|
|
|
$this->_migration = $migration;
|
2014-07-06 08:18:11 -05:00
|
|
|
View::share('menu', 'home');
|
2014-07-04 00:22:16 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* Dev method
|
|
|
|
*/
|
|
|
|
public function dev()
|
|
|
|
{
|
2014-07-08 07:04:02 -05:00
|
|
|
$file = Config::get('dev.import');
|
2014-07-15 15:16:29 -05:00
|
|
|
if (file_exists($file)) {
|
2014-07-08 07:04:02 -05:00
|
|
|
$user = User::find(1);
|
2014-07-15 15:16:29 -05:00
|
|
|
|
|
|
|
/** @noinspection PhpParamsInspection */
|
2014-07-08 07:04:02 -05:00
|
|
|
Auth::login($user);
|
|
|
|
/** @var Firefly\Helper\Migration\MigrationHelperInterface $migration */
|
|
|
|
$migration = App::make('Firefly\Helper\Migration\MigrationHelperInterface');
|
|
|
|
$migration->loadFile($file);
|
|
|
|
if ($migration->validFile()) {
|
|
|
|
$migration->migrate();
|
2014-07-16 14:11:43 -05:00
|
|
|
} else {
|
2014-07-25 06:02:01 -05:00
|
|
|
throw new \Firefly\Exception\FireflyException('Invalid file.');
|
2014-07-08 07:04:02 -05:00
|
|
|
}
|
|
|
|
}
|
2014-07-28 14:33:32 -05:00
|
|
|
|
2014-07-25 06:02:01 -05:00
|
|
|
return '<a href="' . route('index') . '">home</a>';
|
2014-07-20 11:24:27 -05:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2014-07-04 00:22:16 -05:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return View::make('migrate.index');
|
|
|
|
}
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
|
|
|
*/
|
2014-07-04 00:22:16 -05:00
|
|
|
public function postIndex()
|
|
|
|
{
|
|
|
|
if (Input::hasFile('exportFile')) {
|
|
|
|
|
|
|
|
// get content:
|
|
|
|
$file = Input::file('exportFile');
|
|
|
|
$path = $file->getRealPath();
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
$this->_migration->loadFile($path);
|
2014-07-04 00:22:16 -05:00
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
if (!$this->_migration->validFile()) {
|
2014-07-04 00:22:16 -05:00
|
|
|
return View::make('error')->with('message', 'Invalid JSON content.');
|
|
|
|
}
|
2014-07-15 15:16:29 -05:00
|
|
|
$this->_migration->migrate();
|
2014-07-28 14:33:32 -05:00
|
|
|
|
2014-07-05 12:44:26 -05:00
|
|
|
return Redirect::route('index');
|
2014-06-30 03:47:14 -05:00
|
|
|
} else {
|
2014-07-05 12:44:26 -05:00
|
|
|
return View::make('error')->with('message', 'No file selected');
|
2014-06-30 03:47:14 -05:00
|
|
|
}
|
2014-06-30 00:26:38 -05:00
|
|
|
}
|
|
|
|
}
|