1 updater.inc public static Updater::getProjectType($directory)

Return the project type from a Backdrop info file or directory.

Parameters

string $directory: Stream wrapper to directory to get the type from.

Return value

string: The type of the project, either "core", "module", "theme", or "layout".

Throws

UpdaterException

File

core/includes/updater.inc, line 187
Classes used for updating various files in the Backdrop webroot. These classes use a FileTransfer object to actually perform the operations. Normally, the FileTransfer is provided when the site owner is redirected to authorize.php as part of a…

Class

Updater
Base class for Updaters used in Backdrop.

Code

public static function getProjectType($directory) {
  if (basename($directory) == 'backdrop') {
    $realpath = backdrop_realpath($directory);
    if (is_dir($realpath . '/core')) {
      return 'core';
    }
    else {
      $message = t('Updating core from @directory was attempted, but either it doesn\'t contain a "core" directory, or it isn\'t accessible. You may need to update manually.', array('@directory' => $directory));
      throw new UpdaterException($message);
    }
  }
  else {
    $info_file = self::findInfoFile($directory);
    $info = backdrop_parse_info_file($info_file);
    if (empty($info)) {
      throw new UpdaterException(t('Unable to parse info file: %info_file.', array('%info_file' => $info_file)));
    }
    if (empty($info['type'])) {
      throw new UpdaterException(t("The info file (%info_file) does not define a 'type' attribute.", array('%info_file' => $info_file)));
    }

    return $info['type'];
  }
}