[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/content_access/ -> content_access.install (source)

   1  <?php
   2  // $Id: content_access.install,v 1.1.4.3 2008/10/28 13:36:17 fago Exp $
   3  
   4  /**
   5   * Implementation of hook_install().
   6   */
   7  function content_access_install() {
   8    // Create tables.
   9    drupal_install_schema('content_access');
  10  }
  11  
  12  /**
  13   * Implementation of hook_uninstall().
  14   */
  15  function content_access_uninstall() {
  16    variable_del('content_access_settings');
  17    // Remove tables.
  18    drupal_uninstall_schema('content_access');
  19  }
  20  
  21  /**
  22   * Implementation of hook_schema().
  23   */
  24  function content_access_schema() {
  25    $schema['content_access'] = array(
  26      'fields' => array(
  27        'nid' => array(
  28          'type' => 'int',
  29          'unsigned' => TRUE,
  30          'not null' => TRUE,
  31          'default' => 0
  32          ),
  33        'settings' => array(
  34          'type' => 'text',
  35          'not null' => FALSE,
  36          'size' => 'medium'
  37          ),
  38      ),
  39      'primary key' => array('nid')
  40    );
  41    return $schema;
  42  }
  43  
  44  
  45  /**
  46   * Upgrade from d5 to d6
  47   */
  48  function content_access_update_6001() {
  49    drupal_load('module', 'content_access');
  50    module_load_include('inc', 'content_access', 'content_access.admin');
  51  
  52    // Migrate old ca settings to new available d6 permissions
  53    $permissions = content_access_get_permissions_by_role();
  54    $settings = content_access_get_settings();
  55    
  56    foreach (node_get_types('names') as $type => $type_name) {
  57      foreach (array('update', 'delete') as $op) {
  58        // Set permission for roles that are allowed to access
  59        foreach (content_access_get_settings($op, $type) as $rid => $value) {
  60          if (is_numeric($rid)) {
  61            $permissions[$rid][ content_access_get_permission_by_op($op, $type) ] = TRUE;
  62          }
  63          else if ($rid == 'author') {
  64            // CA 5.x let authors access, but only if they were authenticated. So we set the d6 permissions like this.
  65            $permissions[DRUPAL_AUTHENTICATED_RID][ content_access_get_permission_by_op($op . '_own', $type) ] = TRUE;
  66          }
  67        }
  68        // Make sure to delete the old setting, so that the defaults (permissions) will be used.
  69        unset($settings[$op][$type]);
  70      }
  71    }
  72    content_access_save_permissions($permissions);
  73    content_access_set_settings($settings);
  74  
  75    // Rebuild node access for all nodes
  76    node_access_needs_rebuild(TRUE);
  77  
  78    return array();
  79  }
  80  


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7