Projet

Général

Profil

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

root / drupal7 / sites / all / modules / entity / tests / entity_test.install @ 503b3f7b

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('users' => 'uid'),
55
      'name' => array('entity_test_types' => 'name'),
56
    ),
57
    'primary key' => array('pid'),
58
  );
59

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

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

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

    
162
  return $schema;
163
}
164