You are here

class HostingFieldCleanup in Aegir Objects 7.3

@file The HostingFieldCleanup class.

Hierarchy

Expanded class hierarchy of HostingFieldCleanup

File

classes/HostingFieldCleanup.inc, line 6
The HostingFieldCleanup class.

View source
class HostingFieldCleanup {

  // The module for which we're handling cleanup.
  protected $module = FALSE;
  public function __construct($module) {
    $this->module = $module;
  }

  /**
   * Call this method when disabling a module.
   */
  public function disableModule() {
    return $this
      ->deleteFieldInstances();
  }

  /**
   * Call this method when uninstalling a module.
   */
  public function uninstallModule() {
    return $this
      ->deleteFieldData();
  }

  /**
   * Delete all fields instances defined in this module from their bundles.
   */
  protected function deleteFieldInstances() {
    if (module_load_include('inc', $this->module, $this->module . '.features.field_instance')) {
      $function = $this->module . '_field_default_field_instances';
      if (function_exists($function)) {
        foreach ($function() as $instance) {
          field_delete_instance($instance, FALSE);
        }
      }
    }
  }

  /**
   * Delete data for all fields defined in this module.
   */
  protected function deleteFieldData() {
    if (module_load_include('inc', $this->module, $this->module . '.features.field_base')) {
      $function = $this->module . '_field_default_field_bases';
      if (function_exists($function)) {
        $fields = array_keys($function());
        foreach ($fields as $field) {
          field_delete_field($field);
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HostingFieldCleanup::$module protected property
HostingFieldCleanup::deleteFieldData protected function Delete data for all fields defined in this module.
HostingFieldCleanup::deleteFieldInstances protected function Delete all fields instances defined in this module from their bundles.
HostingFieldCleanup::disableModule public function Call this method when disabling a module.
HostingFieldCleanup::uninstallModule public function Call this method when uninstalling a module.
HostingFieldCleanup::__construct public function