|
@@ -349,49 +349,69 @@ function tripal_core_custom_tables_schema() {
|
|
|
*
|
|
|
*/
|
|
|
function tripal_core_update_7200() {
|
|
|
-
|
|
|
- // add an mview column to the tripal_custom_tables table so we
|
|
|
- // can associate which of the custom tables are also mviews
|
|
|
- if (!db_field_exists('tripal_custom_tables', 'mview_id')) {
|
|
|
- $spec = array(
|
|
|
- 'type' => 'int',
|
|
|
- 'not NULL' => FALSE
|
|
|
- );
|
|
|
- $keys = array(
|
|
|
- 'foreign keys' => array(
|
|
|
- 'tripal_mviews' => array(
|
|
|
- 'table' => 'tripal_mviews',
|
|
|
- 'columns' => array(
|
|
|
- 'mview_id' => 'mview_id'
|
|
|
+ try {
|
|
|
+ // add an mview column to the tripal_custom_tables table so we
|
|
|
+ // can associate which of the custom tables are also mviews
|
|
|
+ if (!db_field_exists('tripal_custom_tables', 'mview_id')) {
|
|
|
+ $spec = array(
|
|
|
+ 'type' => 'int',
|
|
|
+ 'not NULL' => FALSE
|
|
|
+ );
|
|
|
+ $keys = array(
|
|
|
+ 'foreign keys' => array(
|
|
|
+ 'tripal_mviews' => array(
|
|
|
+ 'table' => 'tripal_mviews',
|
|
|
+ 'columns' => array(
|
|
|
+ 'mview_id' => 'mview_id'
|
|
|
+ ),
|
|
|
),
|
|
|
),
|
|
|
- ),
|
|
|
- );
|
|
|
- db_add_field('tripal_custom_tables', 'mview_id', $spec, $keys);
|
|
|
+ );
|
|
|
+ db_add_field('tripal_custom_tables', 'mview_id', $spec, $keys);
|
|
|
+
|
|
|
+ // the foreign key specification doesn't really add one to the
|
|
|
+ // Drupal schema, it is just used internally, but we want one
|
|
|
+ db_query('
|
|
|
+ ALTER TABLE {tripal_custom_tables}
|
|
|
+ ADD CONSTRAINT tripal_custom_tables_fk1
|
|
|
+ FOREIGN KEY (mview_id) REFERENCES {tripal_mviews} (mview_id)
|
|
|
+ ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
|
|
|
+ ');
|
|
|
+ }
|
|
|
|
|
|
- // the foreign key specification doesn't really add one to the
|
|
|
- // Drupal schema, it is just used internally, but we want one
|
|
|
- db_query('
|
|
|
- ALTER TABLE {tripal_custom_tables}
|
|
|
- ADD CONSTRAINT tripal_custom_tables_fk1
|
|
|
- FOREIGN KEY (mview_id) REFERENCES {tripal_mviews} (mview_id)
|
|
|
- ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
|
|
|
- ');
|
|
|
+ // now link the materialized view to it's custom table entry
|
|
|
+ $mviews = db_select('tripal_mviews', 'tmv')
|
|
|
+ ->fields('tmv', array('mview_id', 'mv_table'))
|
|
|
+ ->execute();
|
|
|
+ foreach ($mviews as $mview) {
|
|
|
+ db_update('tripal_custom_tables')
|
|
|
+ ->fields(array(
|
|
|
+ 'mview_id' => $mview->mview_id
|
|
|
+ ))
|
|
|
+ ->condition('table_name', $mview->mv_table)
|
|
|
+ ->execute();
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- // now link the materialized view to it's custom table entry
|
|
|
- $mviews = db_select('tripal_mviews', 'tmv')
|
|
|
- ->fields('tmv', array('mview_id', 'mv_table'))
|
|
|
- ->execute();
|
|
|
- foreach ($mviews as $mview) {
|
|
|
- db_update('tripal_custom_tables')
|
|
|
- ->fields(array(
|
|
|
- 'mview_id' => $mview->mview_id
|
|
|
- ))
|
|
|
- ->condition('table_name', $mview->mv_table)
|
|
|
- ->execute();
|
|
|
-
|
|
|
-
|
|
|
+ catch (\PDOException $e) {
|
|
|
+ $error = $e->getMessage();
|
|
|
+ throw new DrupalUpdateException('Could not update tripal_mviews table and link to custom tables: '. $error);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Fixes missing language for nodes and URL aliases. This may take awhile...
|
|
|
+ *
|
|
|
+ */
|
|
|
+function tripal_core_update_7201() {
|
|
|
+
|
|
|
+ try {
|
|
|
+ $sql = "UPDATE {node} SET language = :language WHERE language = ''";
|
|
|
+ db_query($sql, array(':language' => LANGUAGE_NONE));
|
|
|
+ $sql = "UPDATE {url_alias} SET language = :language WHERE language = ''";
|
|
|
+ db_query($sql, array(':language' => LANGUAGE_NONE));
|
|
|
+ }
|
|
|
+ catch (\PDOException $e) {
|
|
|
+ $error = $e->getMessage();
|
|
|
+ throw new DrupalUpdateException('Could not reset language for nodes and url aliases: '. $error);
|
|
|
}
|
|
|
-
|
|
|
}
|