次のように実装しましたが、うまくいきませんでした。。
class Version201809061627000 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->createTablePlgFeatureContent($schema);
$this->copyContent($schema);
}
protected function createTablePlgFeatureContent(Schema $schema)
{
$table = $schema->createTable('plg_feature_content');
$table->addColumn('id', 'integer', array(
'autoincrement' => true,
));
$table->addColumn('feature_id', 'integer', array(
'notnull' => true,
'unsigned' => false,
));
$table->addColumn('position', 'smallint', array(
'notnull' => true,
'unsigned' => false,
));
$table->addColumn('content', 'text', array(
'notnull' => false,
'default' => null,
));
$table->setPrimaryKey(array('id'));
$table->addForeignKeyConstraint(
'plg_feature_page',
array('feature_id'),
array('id')
);
}
protected function copyContent(Schema $schema)
{
$num = $this->connection->fetchAssoc('SELECT COUNT(*) FROM plg_feature_page');
$id = 1;
for ($i=1; $i<=$num; $i++) {
$this->addSql("INSERT INTO plg_feature_content (id, feature_id, position, content) SELECT ".$id++.", id, 1, content1 FROM plg_feature_page WHERE id=".$i.";");
$this->addSql("INSERT INTO plg_feature_content (id, feature_id, position, content) SELECT ".$id++.", id, 2, content2 FROM plg_feature_page WHERE id=".$i.";");
$this->addSql("INSERT INTO plg_feature_content (id, feature_id, position, content) SELECT ".$id++.", id, 3, content3 FROM plg_feature_page WHERE id=".$i.";");
$this->addSql("INSERT INTO plg_feature_content (id, feature_id, position, content) SELECT ".$id++.", id, 4, content4 FROM plg_feature_page WHERE id=".$i.";");
$this->addSql("INSERT INTO plg_feature_content (id, feature_id, position, content) SELECT ".$id++.", id, 5, content5 FROM plg_feature_page WHERE id=".$i.";");
}
}
public function down(Schema $schema)
{
if ($schema->hasTable('plg_feature_content')) {
$schema->dropTable('plg_feature_content');
}
if ($schema->hasSequence('plg_feature_content_seq')) {
$schema->dropSequence('plg_feature_content_seq');
}
}
}
コンソールから実行したら何も表示されずに終了しました。
$ /Applications/MAMP/bin/php/php5.6.10/bin/php app/console plugin:develop update --code=FeaturePage --path=FeaturePagePlugin110.tar.gz
管理画面からアップデートを試してみたら500エラーになりました。
500エラー?
実装ミスがあると500エラーになるのでしょうか。。
データベースの migration_FeaturePage に今回のマイグレーションバージョンのレコードが追加されていなかったので、コケているのは間違いないと思われます。
----------------
EC-CUBE 《プラチナ》ランクパートナー
トエビス株式会社 田中 宏典
EC-CUBEの機能やデザインのカスタマイズ承ります。