/[drupal]/contributions/modules/pbs/pbs.fieldapi.inc
ViewVC logotype

Diff of /contributions/modules/pbs/pbs.fieldapi.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.13, Tue Sep 8 19:21:42 2009 UTC revision 1.14, Tue Sep 8 21:39:42 2009 UTC
# Line 194  function pbs_precompute_bundle_map() { Line 194  function pbs_precompute_bundle_map() {
194    }    }
195    
196    variable_set('pbs_field_map', $map);    variable_set('pbs_field_map', $map);
197      return $map;
198  }  }
199    
200  /**  /**
# Line 241  function pbs_synchronize_bundle($bundle) Line 242  function pbs_synchronize_bundle($bundle)
242   * Load available fields from an object's bundle table, preventing   * Load available fields from an object's bundle table, preventing
243   * them from being loaded from a field table.   * them from being loaded from a field table.
244   */   */
245  function pbs_field_attach_pre_load($obj_type, $objects, $age, &$skip_fields) {  function pbs_field_attach_pre_load($obj_type, $objects, $age, &$skip_fields, $options) {
246    $etid = _field_sql_storage_etid($obj_type);    $etid = _field_sql_storage_etid($obj_type);
247    $load_current = $age == FIELD_LOAD_CURRENT;    $load_current = $age == FIELD_LOAD_CURRENT;
248    
# Line 281  function pbs_field_attach_pre_load($obj_ Line 282  function pbs_field_attach_pre_load($obj_
282      foreach ($results as $row) {      foreach ($results as $row) {
283        foreach ($bundle_fields[$bundle] as $column_name => $tuple) {        foreach ($bundle_fields[$bundle] as $column_name => $tuple) {
284          list($field_name, $field_id, $item_name, $delta) = $tuple;          list($field_name, $field_id, $item_name, $delta) = $tuple;
285          if (!isset($skip_fields[$field_id])) {  
286            if (!isset($skip_fields[$field_id]) && (!isset($options['field_id']) || $options['field_id'] == $field_id)) {
287            if (!is_null($row->{$column_name})) {            if (!is_null($row->{$column_name})) {
288              // We must explicitly include $delta in the assignment              // We must explicitly include $delta in the assignment
289              // below.  Consider a field 'foo' with two columns, e.g. value              // below.  Consider a field 'foo' with two columns, e.g. value
# Line 378  function pbs_field_attach_pre_update($ob Line 380  function pbs_field_attach_pre_update($ob
380          }          }
381    
382          foreach ($langs_items as $language => $items) {          foreach ($langs_items as $language => $items) {
383              // $obj->field[lang] can be NULL
384              if ($items === NULL) {
385                $items = array();
386              }
387    
388            // field_attach_load() is specified to return data items indexed            // field_attach_load() is specified to return data items indexed
389            // from delta 0, regardless of how they were provided on            // from delta 0, regardless of how they were provided on
390            // save.  It is more efficient to re-index on save than on load.            // save.  It is more efficient to re-index on save than on load.
# Line 557  function x_pbs_field_attach_pre_query($f Line 564  function x_pbs_field_attach_pre_query($f
564  }  }
565    
566  /**  /**
567   * Implementation of hook_field_attach_pre_delete.   * Implementation of hook_field_attach_delete.
  *  
  * When an object's fields are deleted, update its bundle table.  
568   */   */
569  function pbs_field_attach_delete($obj_type, $object) {  function pbs_field_attach_delete($obj_type, $object) {
570    $etid = _field_sql_storage_etid($obj_type);    $etid = _field_sql_storage_etid($obj_type);
# Line 572  function pbs_field_attach_delete($obj_ty Line 577  function pbs_field_attach_delete($obj_ty
577    
578  /**  /**
579   * Implementation of field_attach_delete_revision.   * Implementation of field_attach_delete_revision.
  *  
  * When an object's fields are deleted, update its bundle table.  
580   */   */
581  function pbs_field_attach_delete_revision($obj_type, $object) {  function pbs_field_attach_delete_revision($obj_type, $object) {
582    $etid = _field_sql_storage_etid($obj_type);    $etid = _field_sql_storage_etid($obj_type);
# Line 616  function pbs_field_create_instance($inst Line 619  function pbs_field_create_instance($inst
619  /**  /**
620   * Implementation of hook_field_delete_instance.   * Implementation of hook_field_delete_instance.
621   *   *
622   * When a field is removed from a bundle, just update the bundle map.   * When a field is removed from a bundle, drop the columns and update
623   * We can't delete the columns yet because we need the data for batch   * the bundle map. We have to remove the columns immediately because a
624   * delete.  The instance is marked deleted so we will just ignore the   * new field with the same name may be created later.
  * data.  
625   *   *
626   * TODO: We will remove the columns when the batch delete cleanup   * To support being primary storage, we would have rename the columns
627   * process runs.   * instead and clean them up on batch delete.
628   */   */
629  function pbs_field_delete_instance($instance) {  function pbs_field_delete_instance($instance) {
630      $ret = array();
631    
632      $field = field_info_field($instance['field_name']);
633      if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED) {
634        $bundle_table = pbs_tablename($instance['bundle']);
635        $revision_table = pbs_revision_tablename($instance['bundle']);
636        $schema = (array) module_invoke($field['module'], 'field_schema', $field);
637        for ($i = 0; $i < $field['cardinality']; ++$i) {
638          foreach ($schema['columns'] as $name => $spec) {
639            db_drop_field($ret, $bundle_table, $instance['field_name'] .'_'. $name .'_'. $i);
640            db_drop_field($ret, $revision_table, $instance['field_name'] .'_'. $name .'_'. $i);
641          }
642        }
643      }
644    
645    pbs_precompute_bundle_map();    pbs_precompute_bundle_map();
646  }  }
647    
# Line 644  function pbs_field_attach_create_bundle( Line 661  function pbs_field_attach_create_bundle(
661   * Rename the bundle tables.   * Rename the bundle tables.
662   */   */
663  function pbs_field_attach_rename_bundle($old_bundle, $new_bundle) {  function pbs_field_attach_rename_bundle($old_bundle, $new_bundle) {
664    pbs_precompute_bundle_map();    $ret = array();
665    db_rename_table($ret, pbs_tablename($old_bundle), pbs_tablename($new_bundle));    db_rename_table($ret, pbs_tablename($old_bundle), pbs_tablename($new_bundle));
666    db_rename_table($ret, pbs_revision_tablename($old_bundle), pbs_revision_tablename($new_bundle));    db_rename_table($ret, pbs_revision_tablename($old_bundle), pbs_revision_tablename($new_bundle));
667      pbs_precompute_bundle_map();
668  }  }
669    
670  /**  /**
671   * Implementation of hook_field_attach_delete_bundle.   * Implementation of hook_field_attach_delete_bundle.
672   *   *
673   * When a bundle is deleted bundle, just update the bundle map.  We   * When a bundle is deleted bundle, drop the bundle tables and update
674   * can't delete the bundle table yet because we need the data for   * the bundle map.  We have to drop the tables immediately because a
675   * batch delete.  The bundle's instances are marked deleted so the   * new bundle with the same name may be created later.
676   * data will be ignored.  We will drop the table when the batch   *
677   * delete cleanup process runs (not yet implemented).   * To support being primary storage, we would have rename the tables
678     * instead and clean them up on batch delete.
679   */   */
680  function pbs_field_attach_delete_bundle($bundle) {  function pbs_field_attach_delete_bundle($bundle) {
681      $ret = array();
682      db_drop_table($ret, pbs_tablename($bundle));
683      db_drop_table($ret, pbs_revision_tablename($bundle));
684    pbs_precompute_bundle_map();    pbs_precompute_bundle_map();
685  }  }
686    

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.2