Use aliases when migrating data. Fixes #2240
This commit is contained in:
@@ -96,7 +96,9 @@ class IntegrationServiceProvider extends ServiceProvider
|
||||
protected function registerSystem()
|
||||
{
|
||||
$this->app->singleton(SystemContract::class, function (Container $app) {
|
||||
return new System();
|
||||
$config = $app['config'];
|
||||
|
||||
return new System($config);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,8 @@ class StatusPageController extends AbstractApiController
|
||||
return app(DateFactory::class)->make($incident->occurred_at)->toDateString();
|
||||
});
|
||||
|
||||
dd($allIncidents);
|
||||
|
||||
// Add in days that have no incidents
|
||||
if (Config::get('setting.only_disrupted_days') === false) {
|
||||
foreach ($incidentDays as $i) {
|
||||
|
||||
@@ -31,4 +31,11 @@ interface System
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion();
|
||||
|
||||
/**
|
||||
* Get the table prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTablePrefix();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Integrations\Core;
|
||||
use CachetHQ\Cachet\Integrations\Contracts\System as SystemContract;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
|
||||
/**
|
||||
* This is the core system class.
|
||||
@@ -22,6 +23,25 @@ use CachetHQ\Cachet\Models\Incident;
|
||||
*/
|
||||
class System implements SystemContract
|
||||
{
|
||||
/**
|
||||
* The illuminate config instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Create a new system instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Repository $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entire system status.
|
||||
*
|
||||
@@ -80,4 +100,16 @@ class System implements SystemContract
|
||||
{
|
||||
return CACHET_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the table prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTablePrefix()
|
||||
{
|
||||
$driver = $this->config->get('database.default');
|
||||
|
||||
return $this->config->get("database.connections.{$driver}.prefix");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use CachetHQ\Cachet\Integrations\Contracts\System;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -28,7 +29,10 @@ class AlterTableIncidentsAddOccurredAtColumn extends Migration
|
||||
});
|
||||
|
||||
// We need a better way of handling data migrations...
|
||||
DB::update('UPDATE incidents SET occurred_at = created_at');
|
||||
$system = app(System::class);
|
||||
$prefix = $system->getTablePrefix();
|
||||
|
||||
DB::update("UPDATE {$prefix}incidents SET occurred_at = created_at");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use CachetHQ\Cachet\Integrations\Contracts\System;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -24,7 +25,9 @@ class AlterTableIncidentsRemoveScheduledColumns extends Migration
|
||||
public function up()
|
||||
{
|
||||
// We need a better way of handling data migrations...
|
||||
DB::update('INSERT INTO schedules (name, message, scheduled_at, created_at, updated_at) SELECT name, message, scheduled_at, created_at, updated_at FROM incidents WHERE scheduled_at IS NOT NULL');
|
||||
$system = app(System::class);
|
||||
$prefix = $system->getTablePrefix();
|
||||
DB::update("INSERT INTO {$prefix}schedules (name, message, scheduled_at, created_at, updated_at) SELECT name, message, scheduled_at, created_at, updated_at FROM {$prefix}incidents WHERE scheduled_at IS NOT NULL");
|
||||
|
||||
DB::table('incidents')->whereNotNull('scheduled_at')->delete();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user