123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- <?php
- define('UUID_UPGRADE_VAR', 'uuid_upgrade_in_progress');
- module_load_include('inc', 'uuid', 'uuid.entity');
- function uuid_schema_field_definition() {
- return array(
- 'type' => 'char',
- 'length' => 36,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The Universally Unique Identifier.',
- );
- }
- function uuid_schema_alter(array &$schema) {
- $field_info = uuid_schema_field_definition();
- $key_names = array(
- 'base table' => 'uuid',
- 'revision table' => 'revision uuid',
- );
- foreach (uuid_get_core_entity_info() as $entity_info) {
- foreach ($key_names as $table_type => $key_name) {
- if (isset($entity_info[$table_type], $entity_info['entity keys'][$key_name])) {
- $field_name = $entity_info['entity keys'][$key_name];
- $properties = array(
- 'fields' => $field_info,
- 'indexes' => array($field_name),
- );
- foreach ($properties as $property => $value) {
- $schema[$entity_info[$table_type]][$property][$field_name] = $value;
- }
- }
- }
- }
- }
- function uuid_install() {
- _uuid_install_uuid_fields();
- module_load_include('inc', 'uuid');
- uuid_sync_all();
- }
- function _uuid_install_uuid_fields() {
- $field = uuid_schema_field_definition();
- foreach (uuid_get_core_entity_info() as $info) {
- if (!db_field_exists($info['base table'], $info['entity keys']['uuid'])) {
- db_add_field($info['base table'], $info['entity keys']['uuid'], $field);
- db_add_index($info['base table'], $info['entity keys']['uuid'], array($info['entity keys']['uuid']));
- }
- if (!empty($info['revision table']) && !empty($info['entity keys']['revision uuid'])) {
- if (!db_field_exists($info['revision table'], $info['entity keys']['revision uuid'])) {
- db_add_field($info['revision table'], $info['entity keys']['revision uuid'], $field);
- db_add_index($info['revision table'], $info['entity keys']['revision uuid'], array($info['entity keys']['revision uuid']));
- }
- }
- }
- }
- function uuid_uninstall() {
- foreach (uuid_get_core_entity_info() as $info) {
- if (db_field_exists($info['base table'], $info['entity keys']['uuid'])) {
- db_drop_field($info['base table'], $info['entity keys']['uuid']);
- db_drop_index($info['base table'], $info['entity keys']['uuid']);
- }
- if (!empty($info['revision table']) && !empty($info['entity keys']['revision uuid'])) {
- if (db_field_exists($info['revision table'], $info['entity keys']['revision uuid'])) {
- db_drop_field($info['revision table'], $info['entity keys']['revision uuid']);
- db_drop_index($info['revision table'], $info['entity keys']['revision uuid']);
- }
- }
- }
- }
- function uuid_modules_installed($modules) {
-
-
- uuid_install();
- }
- function uuid_update_6001() {
- $ret = array();
- db_create_table($ret, 'uuid_vocabulary', uuid_table_schema('vocabulary', 'vid'));
- db_create_table($ret, 'uuid_term_data', uuid_table_schema('term_data', 'tid'));
- return $ret;
- }
- function uuid_update_6002() {
- $ret = array();
- foreach (uuid_schema() as $table => $schema) {
- db_drop_index($ret, $table, $table . '_uuid_idx');
- db_add_unique_key($ret, $table, $table . '_uuid_key', array('uuid'));
- }
- return $ret;
- }
- function uuid_update_6003() {
- $ret = array();
- db_create_table($ret, 'uuid_comments', uuid_table_schema('comments', 'cid'));
- return $ret;
- }
- function uuid_update_6004() {
- $ret = array();
-
- $tables = uuid_schema();
- $spec = $tables['uuid_node']['fields']['uuid'];
- foreach ($tables as $tablename => $schema) {
- if (db_table_exists($tablename)) {
- db_change_field($ret, $tablename, 'uuid', 'uuid', $spec);
- }
- }
- return $ret;
- }
- function uuid_update_6005() {
- $ret = array();
- if (db_table_exists('uuid_node_revisions')) {
-
- $schema = uuid_schema();
- $spec = $schema['uuid_node_revisions']['fields']['nid'];
- db_add_field($ret, 'uuid_node_revisions', 'nid', $spec);
-
-
- $result = db_query('SELECT nr.nid, nr.vid FROM {node_revisions} AS nr LEFT JOIN {uuid_node_revisions} AS unr ON unr.vid=nr.vid WHERE unr.nid=%d', 0);
- while ($item = db_fetch_object($result)) {
- $ret[] = update_sql('UPDATE {uuid_node_revisions} SET nid=' . (int) $item->nid . ' WHERE vid=' . (int) $item->vid);
- }
-
- $result = db_query('SELECT nr.nid, nr.vid FROM {node_revisions} AS nr LEFT JOIN {uuid_node_revisions} AS unr ON unr.vid=nr.vid WHERE unr.nid IS NULL');
- while ($item = db_fetch_object($result)) {
- $ret[] = update_sql(sprintf("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES(%d, '%s', %d)", $item->vid, uuid_uuid(), $item->nid));
- }
-
- $ret[] = update_sql('DELETE FROM {uuid_node_revisions} WHERE nid=0');
- }
- return $ret;
- }
- function uuid_update_7100() {
- $types = array(
- 'nodes',
- 'users',
- 'taxonomy',
- 'comments',
- );
- foreach ($types as $type) {
- variable_del('uuid_automatic_for_' . $type);
- }
- return array();
- }
- function uuid_update_7101() {
- drupal_flush_all_caches();
- }
- function uuid_update_7102() {
-
-
- module_load_include('module', 'uuid', 'uuid');
- _uuid_install_uuid_fields();
- uuid_sync_all();
- }
- function uuid_update_7103() {
-
-
- $info = entity_get_info();
- $uuids = array(
- 'node' => array(
- 'b0558664-c94b-3674-d9df-3e1696b2e471',
- '5e3d8bbe-a1f2-f2d4-fdc0-71e6c23aa837',
- ),
- 'user' => array(
- '7cf875e6-dc15-4404-f190-5a7c3e91d14c',
- ),
- );
-
- if (isset($info['taxonomy_term'])) {
- $uuids['taxonomy_term'] = array(
- 'bcb92ce8-2236-e264-65c8-0c163ae716d1',
- '4293a15c-531a-6164-7d1b-668ed019a6bd',
- 'af738a46-f278-cf84-d94d-9e03879fd71e',
- );
- }
- foreach (array_keys($uuids) as $entity_type) {
- $info = entity_get_info($entity_type);
- $entity_ids = entity_get_id_by_uuid($entity_type, $uuids[$entity_type]);
- $entities = entity_load($entity_type, $entity_ids);
- foreach ($entities as $entity) {
-
- $entity->{$info['entity keys']['label']} = $entity->{$info['entity keys']['label']} . ' (UUID example)';
-
- if ($entity_type == 'user' && $rid = array_search('administrator', $entity->roles)) {
- unset($entity->roles[$rid]);
- }
- entity_save($entity_type, $entity);
- }
- }
- }
|