2019-11-27 22:19:20 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Installer\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Contracts\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Modules\Installer\Services\Importer\ImporterService;
|
|
|
|
|
|
|
|
class ImporterController extends Controller
|
|
|
|
{
|
|
|
|
private $importerSvc;
|
|
|
|
|
|
|
|
public function __construct(ImporterService $importerSvc)
|
|
|
|
{
|
|
|
|
$this->importerSvc = $importerSvc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the main page for the importer; show form for the admin email
|
|
|
|
* and the credentials for the other database
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
2019-12-02 22:57:35 +08:00
|
|
|
app('debugbar')->disable(); // saves the query logging
|
|
|
|
|
2019-11-27 22:19:20 +08:00
|
|
|
return view('installer::importer/step1-configure');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The post from the above
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function config(Request $request)
|
|
|
|
{
|
2019-12-02 22:57:35 +08:00
|
|
|
app('debugbar')->disable(); // saves the query logging
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Save the credentials to use later
|
|
|
|
$this->importerSvc->saveCredentialsFromRequest($request);
|
|
|
|
|
|
|
|
// Generate the import manifest
|
|
|
|
$manifest = $this->importerSvc->generateImportManifest();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error($e->getMessage());
|
|
|
|
// Send it to run, step1
|
|
|
|
return view('installer::importer/error', [
|
|
|
|
'error' => $e->getMessage(),
|
|
|
|
]);
|
|
|
|
}
|
2019-11-27 22:19:20 +08:00
|
|
|
|
|
|
|
// Send it to run, step1
|
2019-12-02 22:57:35 +08:00
|
|
|
return view('installer::importer/step2-processing', [
|
|
|
|
'manifest' => $manifest,
|
|
|
|
]);
|
2019-11-27 22:19:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the importer. Pass in query string with a few different parameters:
|
|
|
|
*
|
|
|
|
* stage=STAGE NAME
|
|
|
|
* start=record_start
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
2019-12-02 22:57:35 +08:00
|
|
|
* @throws \Exception
|
|
|
|
*
|
2019-11-27 22:19:20 +08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function run(Request $request)
|
|
|
|
{
|
2019-12-02 22:57:35 +08:00
|
|
|
app('debugbar')->disable(); // saves the query logging
|
2019-11-27 22:19:20 +08:00
|
|
|
|
2019-12-02 22:57:35 +08:00
|
|
|
$importer = $request->input('importer');
|
|
|
|
$start = $request->input('start');
|
2019-11-27 22:19:20 +08:00
|
|
|
|
2019-12-02 22:57:35 +08:00
|
|
|
Log::info('Starting stage '.$importer.' from offset '.$start);
|
2019-11-27 22:19:20 +08:00
|
|
|
|
2019-12-02 22:57:35 +08:00
|
|
|
$this->importerSvc->run($importer, $start);
|
2019-11-27 22:19:20 +08:00
|
|
|
|
2019-12-02 22:57:35 +08:00
|
|
|
return response()->json([
|
|
|
|
'message' => 'completed',
|
|
|
|
]);
|
|
|
|
}
|
2019-11-27 22:19:20 +08:00
|
|
|
|
2019-12-02 22:57:35 +08:00
|
|
|
/**
|
|
|
|
* Complete the import
|
|
|
|
*/
|
|
|
|
public function complete()
|
|
|
|
{
|
|
|
|
return redirect('/');
|
2019-11-27 22:19:20 +08:00
|
|
|
}
|
|
|
|
}
|