Open Monograph Press  3.3.0
PKPv3_3_0UpgradeMigration.inc.php
1 <?php
2 
14 use Illuminate\Database\Migrations\Migration;
15 use Illuminate\Database\Schema\Builder;
16 use Illuminate\Database\Schema\Blueprint;
17 use Illuminate\Database\Capsule\Manager as Capsule;
18 
19 class PKPv3_3_0UpgradeMigration extends Migration {
24  public function up() {
25  Capsule::schema()->table('submissions', function (Blueprint $table) {
26  // pkp/pkp-lib#3572 Remove OJS 2.x upgrade tools
27  $table->dropColumn('locale');
28  // pkp/pkp-lib#2493 Remove obsolete columns
29  $table->dropColumn('section_id');
30  });
31  Capsule::schema()->table('publication_settings', function (Blueprint $table) {
32  // pkp/pkp-lib#6096 DB field type TEXT is cutting off long content
33  $table->mediumText('setting_value')->nullable()->change();
34  });
35  Capsule::schema()->table('authors', function (Blueprint $table) {
36  // pkp/pkp-lib#2493 Remove obsolete columns
37  $table->dropColumn('submission_id');
38  });
39  Capsule::schema()->table('author_settings', function (Blueprint $table) {
40  // pkp/pkp-lib#2493 Remove obsolete columns
41  $table->dropColumn('setting_type');
42  });
43  Capsule::schema()->table('announcements', function (Blueprint $table) {
44  // pkp/pkp-lib#5865 Change announcement expiry format in database
45  $table->date('date_expire')->change();
46  });
47 
48  // Transitional: The stage_id column may have already been added by the ADODB schema toolset
49  if (!Capsule::schema()->hasColumn('email_templates_default', 'stage_id')) {
50  Capsule::schema()->table('email_templates_default', function (Blueprint $table) {
51  // pkp/pkp-lib#4796 stage ID as a filter parameter to email templates
52  $table->bigInteger('stage_id')->nullable();
53  });
54  }
55 
56  // pkp/pkp-lib#6093 Don't allow nulls (previously an upgrade workaround)
57  Capsule::schema()->table('user_settings', function (Blueprint $table) {
58  $table->bigInteger('assoc_type')->default(0)->change();
59  $table->bigInteger('assoc_id')->default(0)->change();
60  });
61  Capsule::schema()->table('announcement_types', function (Blueprint $table) {
62  $table->bigInteger('assoc_type')->change();
63  });
64  Capsule::schema()->table('email_templates', function (Blueprint $table) {
65  $table->bigInteger('context_id')->default(0)->change();
66  });
67  Capsule::schema()->table('genres', function (Blueprint $table) {
68  $table->bigInteger('seq')->change();
69  $table->smallInteger('supplementary')->default(0)->change();
70  });
71  Capsule::schema()->table('event_log', function (Blueprint $table) {
72  $table->bigInteger('assoc_type')->change();
73  $table->bigInteger('assoc_id')->change();
74  });
75  Capsule::schema()->table('email_log', function (Blueprint $table) {
76  $table->bigInteger('assoc_type')->change();
77  $table->bigInteger('assoc_id')->change();
78  });
79  Capsule::schema()->table('notes', function (Blueprint $table) {
80  $table->bigInteger('assoc_type')->change();
81  $table->bigInteger('assoc_id')->change();
82  });
83  Capsule::schema()->table('review_forms', function (Blueprint $table) {
84  $table->bigInteger('assoc_type')->change();
85  $table->bigInteger('assoc_id')->change();
86  });
87  Capsule::schema()->table('review_assignments', function (Blueprint $table) {
88  $table->bigInteger('review_round_id')->change();
89  });
90  Capsule::schema()->table('authors', function (Blueprint $table) {
91  $table->bigInteger('publication_id')->change();
92  });
93  Capsule::schema()->table('edit_decisions', function (Blueprint $table) {
94  $table->bigInteger('review_round_id')->change();
95  });
96  Capsule::connection()->unprepared('UPDATE review_assignments SET review_form_id=NULL WHERE review_form_id=0');
97 
98  $this->_populateEmailTemplates();
99  $this->_makeRemoteUrlLocalizable();
100  }
101 
106  public function down() {
108  }
109 
114  private function _populateEmailTemplates() {
115  $xmlDao = new XMLDAO();
116  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO');
117  $data = $xmlDao->parseStruct($emailTemplateDao->getMainEmailTemplatesFilename(), array('email'));
118  foreach ($data['email'] as $template) {
119  $attr = $template['attributes'];
120  if (array_key_exists('stage_id', $attr)) {
121  Capsule::table('email_templates_default')->where('email_key', $attr['key'])->update(array('stage_id' => $attr['stage_id']));
122  }
123  }
124  }
125 
130  private function _makeRemoteUrlLocalizable() {
131  $contextService = Services::get('context');
132  $contextIds = $contextService->getIds();
133  foreach ($contextIds as $contextId) {
134  $context = $contextService->get($contextId);
135  $locales = $context->getData('supportedLocales');
136 
137  $navigationItems = Capsule::table('navigation_menu_items')->where('context_id', $contextId)->pluck('url', 'navigation_menu_item_id')->filter()->all();
138  foreach ($navigationItems as $navigation_menu_item_id => $url) {
139  foreach ($locales as $locale) {
140  Capsule::table('navigation_menu_item_settings')->insert([
141  'navigation_menu_item_id' => $navigation_menu_item_id,
142  'locale' => $locale,
143  'setting_name' => 'remoteUrl',
144  'setting_value' => $url,
145  'setting_type' => 'string'
146  ]);
147  }
148  }
149  }
150 
151  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
152  $site = $siteDao->getSite();
153  $supportedLocales = $site->getSupportedLocales();
154  $navigationItems = Capsule::table('navigation_menu_items')->where('context_id', '0')->pluck('url', 'navigation_menu_item_id')->filter()->all();
155  foreach ($navigationItems as $navigation_menu_item_id => $url) {
156  foreach ($supportedLocales as $locale) {
157  Capsule::table('navigation_menu_item_settings')->insert([
158  'navigation_menu_item_id' => $navigation_menu_item_id,
159  'locale' => $locale,
160  'setting_name' => 'remoteUrl',
161  'setting_value' => $url,
162  'setting_type' => 'string'
163  ]);
164  }
165  }
166 
167  Capsule::schema()->table('navigation_menu_items', function (Blueprint $table) {
168  $table->dropColumn('url');
169  });
170  }
171 }
XMLDAO
Operations for retrieving and modifying objects from an XML data source.
Definition: XMLDAO.inc.php:19
PKPv3_3_0UpgradeMigration\up
up()
Definition: PKPv3_3_0UpgradeMigration.inc.php:24
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PKP\install\DowngradeNotSupportedException
Definition: DowngradeNotSupportedException.inc.php:15
PKPv3_3_0UpgradeMigration
Definition: PKPv3_3_0UpgradeMigration.inc.php:19
PKPv3_3_0UpgradeMigration\down
down()
Definition: PKPv3_3_0UpgradeMigration.inc.php:106
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49