9a210e0bfec9f44d9a2608d873bdadc86c9e5204
[yaffs-website] / web / core / modules / field / tests / fixtures / update / drupal-8.update_deleted_field_definitions-2931436.php
1 <?php
2 // @codingStandardsIgnoreFile
3
4 /**
5  * @file
6  * Contains SQL necessary to add a deleted field to the node entity type.
7  */
8
9 use Drupal\Core\Database\Database;
10
11 $connection = Database::getConnection();
12
13 // Add the field schema data and the deleted field definitions.
14 $connection->insert('key_value')
15   ->fields([
16     'collection',
17     'name',
18     'value',
19   ])
20   ->values([
21     'collection' => 'entity.storage_schema.sql',
22     'name' => 'node.field_schema_data.field_test',
23     'value' => 'a:2:{s:16:"node__field_test";a:4:{s:11:"description";s:39:"Data storage for node field field_test.";s:6:"fields";a:7:{s:6:"bundle";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:128;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:88:"The field instance bundle to which this row belongs, used when deleting a field instance";}s:7:"deleted";a:5:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:1;s:7:"default";i:0;s:11:"description";s:60:"A boolean indicating whether this data item has been deleted";}s:9:"entity_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:38:"The entity id this data is attached to";}s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:47:"The entity revision id this data is attached to";}s:8:"langcode";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:32;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:37:"The language code for this data item.";}s:5:"delta";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:67:"The sequence number for this data item, used for multi-value fields";}s:16:"field_test_value";a:3:{s:4:"type";s:7:"varchar";s:6:"length";i:254;s:8:"not null";b:1;}}s:11:"primary key";a:4:{i:0;s:9:"entity_id";i:1;s:7:"deleted";i:2;s:5:"delta";i:3;s:8:"langcode";}s:7:"indexes";a:2:{s:6:"bundle";a:1:{i:0;s:6:"bundle";}s:11:"revision_id";a:1:{i:0;s:11:"revision_id";}}}s:25:"node_revision__field_test";a:4:{s:11:"description";s:51:"Revision archive storage for node field field_test.";s:6:"fields";a:7:{s:6:"bundle";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:128;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:88:"The field instance bundle to which this row belongs, used when deleting a field instance";}s:7:"deleted";a:5:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:1;s:7:"default";i:0;s:11:"description";s:60:"A boolean indicating whether this data item has been deleted";}s:9:"entity_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:38:"The entity id this data is attached to";}s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:47:"The entity revision id this data is attached to";}s:8:"langcode";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:32;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:37:"The language code for this data item.";}s:5:"delta";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:67:"The sequence number for this data item, used for multi-value fields";}s:16:"field_test_value";a:3:{s:4:"type";s:7:"varchar";s:6:"length";i:254;s:8:"not null";b:1;}}s:11:"primary key";a:5:{i:0;s:9:"entity_id";i:1;s:11:"revision_id";i:2;s:7:"deleted";i:3;s:5:"delta";i:4;s:8:"langcode";}s:7:"indexes";a:2:{s:6:"bundle";a:1:{i:0;s:6:"bundle";}s:11:"revision_id";a:1:{i:0;s:11:"revision_id";}}}}',
24   ])
25   ->values([
26     'collection' => 'state',
27     'name' => 'field.field.deleted',
28     'value' => 'a:1:{s:36:"5d0d9870-560b-46c4-b838-0dcded0502dd";a:18:{s:4:"uuid";s:36:"5d0d9870-560b-46c4-b838-0dcded0502dd";s:8:"langcode";s:2:"en";s:6:"status";b:1;s:12:"dependencies";a:1:{s:6:"config";a:2:{i:0;s:29:"field.storage.node.field_test";i:1;s:17:"node.type.article";}}s:2:"id";s:23:"node.article.field_test";s:10:"field_name";s:10:"field_test";s:11:"entity_type";s:4:"node";s:6:"bundle";s:7:"article";s:5:"label";s:4:"Test";s:11:"description";s:0:"";s:8:"required";b:0;s:12:"translatable";b:0;s:13:"default_value";a:0:{}s:22:"default_value_callback";s:0:"";s:8:"settings";a:0:{}s:10:"field_type";s:5:"email";s:7:"deleted";b:1;s:18:"field_storage_uuid";s:36:"ce93d7c2-1da7-4a2c-9e6d-b4925e3b129f";}}',
29   ])
30   ->values([
31     'collection' => 'state',
32     'name' => 'field.storage.deleted',
33     'value' => 'a:1:{s:36:"ce93d7c2-1da7-4a2c-9e6d-b4925e3b129f";a:18:{s:4:"uuid";s:36:"ce93d7c2-1da7-4a2c-9e6d-b4925e3b129f";s:8:"langcode";s:2:"en";s:6:"status";b:1;s:12:"dependencies";a:1:{s:6:"module";a:1:{i:0;s:4:"node";}}s:2:"id";s:15:"node.field_test";s:10:"field_name";s:10:"field_test";s:11:"entity_type";s:4:"node";s:4:"type";s:5:"email";s:8:"settings";a:0:{}s:6:"module";s:4:"core";s:6:"locked";b:0;s:11:"cardinality";i:1;s:12:"translatable";b:1;s:7:"indexes";a:0:{}s:22:"persist_with_no_fields";b:0;s:14:"custom_storage";b:0;s:7:"deleted";b:1;s:7:"bundles";a:0:{}}}',
34   ])
35   ->execute();
36
37 // Create and populate the deleted field tables.
38 // @see \Drupal\Core\Entity\Sql\DefaultTableMapping::getDedicatedDataTableName()
39 $deleted_field_data_table_name = "field_deleted_data_" . substr(hash('sha256', 'ce93d7c2-1da7-4a2c-9e6d-b4925e3b129f'), 0, 10);
40 $connection->schema()->createTable($deleted_field_data_table_name, array(
41   'fields' => array(
42     'bundle' => array(
43       'type' => 'varchar_ascii',
44       'not null' => TRUE,
45       'length' => '128',
46       'default' => '',
47     ),
48     'deleted' => array(
49       'type' => 'int',
50       'not null' => TRUE,
51       'size' => 'tiny',
52       'default' => '0',
53     ),
54     'entity_id' => array(
55       'type' => 'int',
56       'not null' => TRUE,
57       'size' => 'normal',
58       'unsigned' => TRUE,
59     ),
60     'revision_id' => array(
61       'type' => 'int',
62       'not null' => TRUE,
63       'size' => 'normal',
64       'unsigned' => TRUE,
65     ),
66     'langcode' => array(
67       'type' => 'varchar_ascii',
68       'not null' => TRUE,
69       'length' => '32',
70       'default' => '',
71     ),
72     'delta' => array(
73       'type' => 'int',
74       'not null' => TRUE,
75       'size' => 'normal',
76       'unsigned' => TRUE,
77     ),
78     'field_test_value' => array(
79       'type' => 'varchar',
80       'not null' => TRUE,
81       'length' => '254',
82     ),
83   ),
84   'primary key' => array(
85     'entity_id',
86     'deleted',
87     'delta',
88     'langcode',
89   ),
90   'indexes' => array(
91     'bundle' => array(
92       'bundle',
93     ),
94     'revision_id' => array(
95       'revision_id',
96     ),
97   ),
98 ));
99
100 $connection->insert($deleted_field_data_table_name)
101 ->fields(array(
102   'bundle',
103   'deleted',
104   'entity_id',
105   'revision_id',
106   'langcode',
107   'delta',
108   'field_test_value',
109 ))
110 ->values(array(
111   'bundle' => 'article',
112   'deleted' => '1',
113   'entity_id' => '1',
114   'revision_id' => '1',
115   'langcode' => 'en',
116   'delta' => '0',
117   'field_test_value' => 'test@test.com',
118 ))
119 ->execute();
120
121 // @see \Drupal\Core\Entity\Sql\DefaultTableMapping::getDedicatedDataTableName()
122 $deleted_field_revision_table_name = "field_deleted_revision_" . substr(hash('sha256', 'ce93d7c2-1da7-4a2c-9e6d-b4925e3b129f'), 0, 10);
123 $connection->schema()->createTable($deleted_field_revision_table_name, array(
124   'fields' => array(
125     'bundle' => array(
126       'type' => 'varchar_ascii',
127       'not null' => TRUE,
128       'length' => '128',
129       'default' => '',
130     ),
131     'deleted' => array(
132       'type' => 'int',
133       'not null' => TRUE,
134       'size' => 'tiny',
135       'default' => '0',
136     ),
137     'entity_id' => array(
138       'type' => 'int',
139       'not null' => TRUE,
140       'size' => 'normal',
141       'unsigned' => TRUE,
142     ),
143     'revision_id' => array(
144       'type' => 'int',
145       'not null' => TRUE,
146       'size' => 'normal',
147       'unsigned' => TRUE,
148     ),
149     'langcode' => array(
150       'type' => 'varchar_ascii',
151       'not null' => TRUE,
152       'length' => '32',
153       'default' => '',
154     ),
155     'delta' => array(
156       'type' => 'int',
157       'not null' => TRUE,
158       'size' => 'normal',
159       'unsigned' => TRUE,
160     ),
161     'field_test_value' => array(
162       'type' => 'varchar',
163       'not null' => TRUE,
164       'length' => '254',
165     ),
166   ),
167   'primary key' => array(
168     'entity_id',
169     'revision_id',
170     'deleted',
171     'delta',
172     'langcode',
173   ),
174   'indexes' => array(
175     'bundle' => array(
176       'bundle',
177     ),
178     'revision_id' => array(
179       'revision_id',
180     ),
181   ),
182 ));
183
184 $connection->insert($deleted_field_revision_table_name)
185 ->fields(array(
186   'bundle',
187   'deleted',
188   'entity_id',
189   'revision_id',
190   'langcode',
191   'delta',
192   'field_test_value',
193 ))
194 ->values(array(
195   'bundle' => 'article',
196   'deleted' => '1',
197   'entity_id' => '1',
198   'revision_id' => '1',
199   'langcode' => 'en',
200   'delta' => '0',
201   'field_test_value' => 'test@test.com',
202 ))
203 ->execute();