Projet

Général

Profil

Paste
Télécharger (4,7 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / entity / tests / entity_test.install @ 7d7b5830

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the entity_test module.
6
 */
7

    
8
/**
9
 * Implements hook_uninstall().
10
 */
11
function entity_test_uninstall() {
12
  // Bypass entity_load() as we cannot use it here.
13
  $types = db_select('entity_test_type', 'et')
14
    ->fields('et')
15
    ->execute()
16
    ->fetchAllAssoc('name');
17

    
18
  foreach ($types as $name => $type) {
19
    field_attach_delete_bundle('entity_test', $name);
20
  }
21
}
22

    
23
/**
24
 * Implements hook_schema().
25
 */
26
function entity_test_schema() {
27
  $schema['entity_test'] = array(
28
    'description' => 'Stores entity_test items.',
29
    'fields' => array(
30
      'pid' => array(
31
        'type' => 'serial',
32
        'not null' => TRUE,
33
        'description' => 'Primary Key: Unique entity_test item ID.',
34
      ),
35
      'name' => array(
36
        'description' => 'The name of the entity_test.',
37
        'type' => 'varchar',
38
        'length' => 32,
39
        'not null' => TRUE,
40
        'default' => '',
41
      ),
42
      'uid' => array(
43
        'type' => 'int',
44
        'unsigned' => TRUE,
45
        'not null' => FALSE,
46
        'default' => NULL,
47
        'description' => "The {users}.uid of the associated user.",
48
      ),
49
    ),
50
    'indexes' => array(
51
      'uid' => array('uid'),
52
    ),
53
    'foreign keys' => array(
54
      'uid' => array(
55
        'table' => 'users',
56
        'columns' => array('uid' => 'uid')
57
      ),
58
      'name' => array(
59
        'table' => 'entity_test_types',
60
        'columns' => array('name' => 'name')
61
      ),
62
    ),
63
    'primary key' => array('pid'),
64
  );
65

    
66
  $schema['entity_test_type'] = array(
67
    'description' => 'Stores information about all defined entity_test types.',
68
    'fields' => array(
69
      'id' => array(
70
        'type' => 'serial',
71
        'not null' => TRUE,
72
        'description' => 'Primary Key: Unique entity_test type ID.',
73
      ),
74
      'name' => array(
75
        'description' => 'The machine-readable name of this entity_test type.',
76
        'type' => 'varchar',
77
        'length' => 32,
78
        'not null' => TRUE,
79
      ),
80
      'label' => array(
81
        'description' => 'The human-readable name of this entity_test type.',
82
        'type' => 'varchar',
83
        'length' => 255,
84
        'not null' => TRUE,
85
        'default' => '',
86
      ),
87
      'weight' => array(
88
        'type' => 'int',
89
        'not null' => TRUE,
90
        'default' => 0,
91
        'size' => 'tiny',
92
        'description' => 'The weight of this entity_test type in relation to others.',
93
      ),
94
      'locked' => array(
95
        'description' => 'A boolean indicating whether the administrator may delete this type.',
96
        'type' => 'int',
97
        'not null' => TRUE,
98
        'default' => 0,
99
        'size' => 'tiny',
100
      ),
101
      'data' => array(
102
        'type' => 'text',
103
        'not null' => FALSE,
104
        'size' => 'big',
105
        'serialize' => TRUE,
106
        'description' => 'A serialized array of additional data related to this entity_test type.',
107
        'merge' => TRUE,
108
      ),
109
      'status' => array(
110
        'type' => 'int',
111
        'not null' => TRUE,
112
        // Set the default to ENTITY_CUSTOM without using the constant as it is
113
        // not safe to use it at this point.
114
        'default' => 0x01,
115
        'size' => 'tiny',
116
        'description' => 'The exportable status of the entity.',
117
      ),
118
      'module' => array(
119
        'description' => 'The name of the providing module if the entity has been defined in code.',
120
        'type' => 'varchar',
121
        'length' => 255,
122
        'not null' => FALSE,
123
      ),
124
    ),
125
    'primary key' => array('id'),
126
    'unique keys' => array(
127
      'name' => array('name'),
128
    ),
129
  );
130

    
131
  // Add schema for the revision-test-entity.
132
  $schema['entity_test2'] = $schema['entity_test'];
133
  $schema['entity_test2']['fields']['revision_id'] = array(
134
    'type' => 'int',
135
    'unsigned' => TRUE,
136
    'not null' => FALSE,
137
    'default' => NULL,
138
    'description' => 'The ID of the entity\'s default revision.',
139
  );
140
  $schema['entity_test2']['fields']['title'] = array(
141
    'type' => 'varchar',
142
    'length' => 255,
143
    'not null' => TRUE,
144
    'default' => '',
145
  );
146

    
147
  $schema['entity_test2_revision'] = $schema['entity_test'];
148
  $schema['entity_test2_revision']['fields']['revision_id'] = array(
149
    'type' => 'serial',
150
    'not null' => TRUE,
151
    'description' => 'Primary Key: Unique revision ID.',
152
  );
153
  $schema['entity_test2_revision']['fields']['pid'] = array(
154
    'type' => 'int',
155
    'unsigned' => TRUE,
156
    'not null' => FALSE,
157
    'default' => NULL,
158
    'description' => 'The ID of the attached entity.',
159
  );
160
  $schema['entity_test2_revision']['fields']['title'] = array(
161
    'type' => 'varchar',
162
    'length' => 255,
163
    'not null' => TRUE,
164
    'default' => '',
165
  );
166
  $schema['entity_test2_revision']['primary key'] = array('revision_id');
167

    
168
  return $schema;
169
}
170