15 public function up() {
17 if (!$this->hasTable(
'metastrings')) {
27 if (!$this->hasTable($table)) {
31 $table = $this->table($table);
33 if (!$table->hasColumn(
'value')) {
34 $table->addColumn(
'value',
'text', [
36 'after' =>
'entity_guid',
37 'limit' => MysqlAdapter::TEXT_LONG,
41 if (!$table->hasColumn(
'name')) {
42 $table->addColumn(
'name',
'text', [
44 'after' =>
'entity_guid',
50 if ($table->hasColumn(
'name_id') && $table->hasColumn(
'value_id')) {
51 $prefix = $this->getAdapter()->getOption(
'table_prefix');
54 if ($table->hasIndexByName(
'name_id')) {
55 $table->removeIndexByName(
'name_id')->save();
58 if ($table->hasIndexByName(
'value_id')) {
59 $table->removeIndexByName(
'value_id')->save();
64 UPDATE {$prefix}{$table->getName()} n_table 65 INNER JOIN {$prefix}metastrings msn ON n_table.name_id = msn.id 66 INNER JOIN {$prefix}metastrings msv ON n_table.value_id = msv.id 67 SET n_table.name = msn.string, 68 n_table.value = msv.string 72 $table->removeColumn(
'name_id');
73 $table->removeColumn(
'value_id');
77 if (!$table->hasIndexByName(
'name')) {
78 $table->addIndex([
'name'], [
85 if (!$table->hasIndexByName(
'value')) {
86 $table->addIndex([
'value'], [
96 $this->table(
'metastrings')->drop()->save();
111 if ($this->hasTable(
'metastrtings')) {
115 $table = $this->table(
'metastrings', [
116 'engine' =>
'MyISAM',
117 'encoding' =>
"utf8",
118 'collation' =>
"utf8_general_ci",
121 $table->addColumn(
'string',
'text', [
125 $table->addIndex([
'string'], [
132 $prefix = $this->getAdapter()->getOption(
'table_prefix');
138 $table = $this->table($table);
140 if (!$table->hasColumn(
'name_id')) {
141 $table->addColumn(
'name_id',
'integer', [
143 'limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_REGULAR,
148 if (!$table->hasColumn(
'value_id')) {
149 $table->addColumn(
'value_id',
'integer', [
151 'limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_REGULAR,
156 if (!$table->hasIndexByName(
'name_id')) {
157 $table->addIndex([
'name_id'], [
162 if (!$table->hasIndexByName(
'value_id')) {
163 $table->addIndex([
'value_id'], [
164 'name' =>
'value_id',
170 $rows = $this->fetchAll(
" 172 FROM {$prefix}{$table->getName()} 175 foreach (
$rows as $row) {
176 $this->table(
'metastrings')->insert([
177 [
'string' => $row[
'name']],
178 [
'string' => $row[
'value']],
184 UPDATE {$prefix}{$table->getName()} n_table 185 INNER JOIN {$prefix}metastrings msn ON n_table.name = msn.string 186 INNER JOIN {$prefix}metastrings msv ON n_table.value = msv.string 187 SET n_table.name_id = msn.id, 188 n_table.value_id = msv.id 191 if ($table->hasIndexByName(
'name')) {
192 $table->removeIndexByName(
'name')->save();
195 if ($table->hasIndexByName(
'value')) {
196 $table->removeIndexByName(
'value')->save();
199 if ($table->hasColumn(
'name')) {
200 $table->removeColumn(
'name');
203 if ($table->hasColumn(
'value')) {
204 $table->removeColumn(
'value');