. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * @file * Install Mica Relation module. */ /** * Implements hook_schema() */ function mica_relation_schema() { $schema['mica_relation'] = array( 'description' => 'Stores relations between content types', 'fields' => array( 'id' => array( 'type' => 'serial', 'not null' => TRUE, 'description' => 'Primary Key: Unique relation ID', ), 'parent_bundle' => array( 'type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '', 'description' => 'The parent content type machine name', ), 'child_bundle' => array( 'type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '', 'description' => 'The child content type machine name', ), 'label' => array( 'description' => 'The human-readable name to be displayed for this relation.', 'type' => 'varchar', 'length' => 80, 'not null' => TRUE, ), 'enabled' => array( 'description' => 'A flag indicating whether the relation is enabled.', 'type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 1, ), 'options' => array( 'description' => 'The options used to configure the relation.', 'type' => 'text', 'serialize' => TRUE, 'not null' => TRUE, ), ) + entity_exportable_schema_fields(), 'indexes' => array( 'parent_index' => array('parent_bundle'), 'enabled' => array('enabled'), ), 'unique keys' => array( 'unique_child' => array('child_bundle'), ), 'primary key' => array('id'), ); return $schema; } /** * Implements hook_install() */ function mica_relation_install() { _mica_relation_import_data(); } /** * Import mica_relation previously exported by mica_core, if any. */ function _mica_relation_import_data() { $export = variable_get('mica_relation_export'); if (isset($export)) { foreach ($export as $relation) { db_insert('mica_relation') ->fields(array( 'id' => $relation->id, 'label' => $relation->label, 'parent_bundle' => $relation->parent_bundle, 'child_bundle' => $relation->child_bundle, 'options' => $relation->options, 'enabled' => $relation->enabled, ))->execute(); } variable_del('mica_relation_export'); } }