getModuleSchemaVersion example

/** * Wrapper method to test protected method moduleExists(). */
  public function moduleExistsWrapper($module) {
    return parent::moduleExists($module);
  }

  /** * Wrapper method to test protected method getModuleSchemaVersion(). */
  public function getModuleSchemaVersionWrapper($module) {
    return parent::getModuleSchemaVersion($module);
  }

  /** * Wrapper method to test protected method variableGet(). */
  public function variableGetWrapper($name$default) {
    return parent::variableGet($name$default);
  }

  /** * {@inheritdoc} */
/** * Table listing user roles. * * @var string */
  protected $userRoleTable;

  /** * {@inheritdoc} */
  public function query() {
    if ($this->getModuleSchemaVersion('system') >= 7000) {
      $this->blockTable = 'block';
      $this->blockRoleTable = 'block_role';
    }
    else {
      $this->blockTable = 'blocks';
      $this->blockRoleTable = 'blocks_roles';
    }
    // Drupal 6 & 7 both use the same name for the user roles table.     $this->userRoleTable = 'role';

    return $this->select($this->blockTable, 'b')->fields('b');
  }
/** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    // format = 0 can happen when the body field is hidden. Set the format to 1     // to avoid migration map issues (since the body field isn't used anyway).     if ($row->getSourceProperty('format') === '0') {
      $row->setSourceProperty('format', $this->filterDefaultFormat);
    }

    if ($this->moduleExists('content') && $this->getModuleSchemaVersion('content') >= 6001) {
      foreach ($this->getFieldValues($row) as $field => $values) {
        $row->setSourceProperty($field$values);
      }
    }

    // Make sure we always have a translation set.     if ($row->getSourceProperty('tnid') == 0) {
      $row->setSourceProperty('tnid', $row->getSourceProperty('nid'));
    }

    return parent::prepareRow($row);
  }
// If we make it to here, the profile module isn't installed.       throw new RequirementsException('Profile module not enabled on source site');
    }
    parent::checkRequirements();
  }

  /** * Helper to set the profile field table names. */
  protected function setTableNames() {
    if (empty($this->fieldTable) || empty($this->valueTable)) {
      if ($this->getModuleSchemaVersion('system') >= 7000) {
        $this->fieldTable = 'profile_field';
        $this->valueTable = 'profile_value';
      }
      else {
        $this->fieldTable = 'profile_fields';
        $this->valueTable = 'profile_values';
      }
    }
  }

}
/** * {@inheritdoc} */
  public function fields() {
    $fields = [
      'aid' => $this->t('Action ID'),
      'type' => $this->t('Module'),
      'callback' => $this->t('Callback function'),
      'parameters' => $this->t('Action configuration'),
    ];
    if ($this->getModuleSchemaVersion('system') >= 7000) {
      $fields['label'] = $this->t('Label of the action');
    }
    else {
      $fields['description'] = $this->t('Action description');
    }
    return $fields;
  }

  /** * {@inheritdoc} */
  
/** * {@inheritdoc} */
  public function checkRequirements() {
    parent::checkRequirements();
    if ($this->pluginDefinition['requirements_met'] === TRUE) {
      if ($source_module = $this->getSourceModule()) {
        if ($this->moduleExists($source_module)) {
          if (isset($this->pluginDefinition['minimum_version'])) {
            $minimum_version = (int) $this->pluginDefinition['minimum_version'];
            $installed_version = (int) $this->getModuleSchemaVersion($source_module);
            if ($minimum_version > $installed_version) {
              throw new RequirementsException('Required minimum version ' . $this->pluginDefinition['minimum_version']['minimum_version' => $this->pluginDefinition['minimum_version']]);
            }
          }
        }
        else {
          throw new RequirementsException('The module ' . $source_module . ' is not enabled in the source site.', ['source_module' => $source_module]);
        }
      }
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.