Open Preprint Systems  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  Capsule::schema()->table('email_templates_default', function (Blueprint $table) {
48  // pkp/pkp-lib#4796 stage ID as a filter parameter to email templates
49  $table->bigInteger('stage_id')->nullable();
50  });
51 
52  // pkp/pkp-lib#6093 Don't allow nulls (previously an upgrade workaround)
53  Capsule::schema()->table('user_settings', function (Blueprint $table) {
54  $table->bigInteger('assoc_type')->default(0)->change();
55  $table->bigInteger('assoc_id')->default(0)->change();
56  });
57  Capsule::schema()->table('announcement_types', function (Blueprint $table) {
58  $table->bigInteger('assoc_type')->change();
59  });
60  Capsule::schema()->table('email_templates', function (Blueprint $table) {
61  $table->bigInteger('context_id')->default(0)->change();
62  });
63  Capsule::schema()->table('genres', function (Blueprint $table) {
64  $table->bigInteger('seq')->change();
65  $table->tinyInteger('supplementary')->default(0)->change();
66  });
67  Capsule::schema()->table('event_log', function (Blueprint $table) {
68  $table->bigInteger('assoc_type')->change();
69  $table->bigInteger('assoc_id')->change();
70  });
71  Capsule::schema()->table('email_log', function (Blueprint $table) {
72  $table->bigInteger('assoc_type')->change();
73  $table->bigInteger('assoc_id')->change();
74  });
75  Capsule::schema()->table('notes', function (Blueprint $table) {
76  $table->bigInteger('assoc_type')->change();
77  $table->bigInteger('assoc_id')->change();
78  });
79  Capsule::schema()->table('review_forms', function (Blueprint $table) {
80  $table->bigInteger('assoc_type')->change();
81  $table->bigInteger('assoc_id')->change();
82  });
83  Capsule::schema()->table('review_assignments', function (Blueprint $table) {
84  $table->bigInteger('review_round_id')->change();
85  });
86  Capsule::schema()->table('authors', function (Blueprint $table) {
87  $table->bigInteger('publication_id')->change();
88  });
89  Capsule::schema()->table('edit_decisions', function (Blueprint $table) {
90  $table->bigInteger('review_round_id')->change();
91  });
92  Capsule::connection()->unprepared('UPDATE review_assignments SET review_form_id=NULL WHERE review_form_id=0');
93 
94  $this->_populateEmailTemplates();
95  $this->_makeRemoteUrlLocalizable();
96  }
97 
102  public function down() {
103  throw new Exception('Downgrade not supported.');
104  }
105 
110  private function _populateEmailTemplates() {
111  $xmlDao = new XMLDAO();
112  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO');
113  $data = $xmlDao->parseStruct($emailTemplateDao->getMainEmailTemplatesFilename(), array('email'));
114  foreach ($data['email'] as $template) {
115  $attr = $template['attributes'];
116  if (array_key_exists('stage_id', $attr)) {
117  Capsule::table('email_templates_default')->where('email_key', $attr['key'])->update(array('stage_id' => $attr['stage_id']));
118  }
119  }
120  }
121 
126  private function _makeRemoteUrlLocalizable() {
127  $contextService = Services::get('context');
128  $contextIds = $contextService->getIds();
129  foreach ($contextIds as $contextId) {
130  $context = $contextService->get($contextId);
131  $locales = $context->getData('supportedLocales');
132 
133  $navigationItems = Capsule::table('navigation_menu_items')->where('context_id', $contextId)->pluck('url', 'navigation_menu_item_id')->filter()->all();
134  foreach ($navigationItems as $navigation_menu_item_id => $url) {
135  foreach ($locales as $locale) {
136  Capsule::table('navigation_menu_item_settings')->insert([
137  'navigation_menu_item_id' => $navigation_menu_item_id,
138  'locale' => $locale,
139  'setting_name' => 'remoteUrl',
140  'setting_value' => $url,
141  'setting_type' => 'string'
142  ]);
143  }
144  }
145  }
146 
147  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
148  $site = $siteDao->getSite();
149  $supportedLocales = $site->getSupportedLocales();
150  $navigationItems = Capsule::table('navigation_menu_items')->where('context_id', '0')->pluck('url', 'navigation_menu_item_id')->filter()->all();
151  foreach ($navigationItems as $navigation_menu_item_id => $url) {
152  foreach ($supportedLocales as $locale) {
153  Capsule::table('navigation_menu_item_settings')->insert([
154  'navigation_menu_item_id' => $navigation_menu_item_id,
155  'locale' => $locale,
156  'setting_name' => 'remoteUrl',
157  'setting_value' => $url,
158  'setting_type' => 'string'
159  ]);
160  }
161  }
162 
163  Capsule::schema()->table('navigation_menu_items', function (Blueprint $table) {
164  $table->dropColumn('url');
165  });
166  }
167 }
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
PKPv3_3_0UpgradeMigration
Definition: PKPv3_3_0UpgradeMigration.inc.php:19
PKPv3_3_0UpgradeMigration\down
down()
Definition: PKPv3_3_0UpgradeMigration.inc.php:102
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49