You are here

feeds_jsonpath_parser.install in Feeds JSONPath Parser 7

Same filename and directory in other branches
  1. 6 feeds_jsonpath_parser.install

Installation file for Feeds JSONPath Parser module.

File

feeds_jsonpath_parser.install
View source
<?php

/**
 * @file
 * Installation file for Feeds JSONPath Parser module.
 */

/**
 * Implements hook_requirements().
 */
function feeds_jsonpath_parser_requirements($phase) {
  $requirements = array();
  if ($phase !== 'runtime' && $phase !== 'install') {
    return $requirements;
  }
  drupal_load('module', 'feeds_jsonpath_parser');
  $t = get_t();
  $requirements['feeds_jsonpath_parser']['title'] = $t('JSONPath library');
  $requirements['feeds_jsonpath_parser']['severity'] = REQUIREMENT_OK;
  $requirements['feeds_jsonpath_parser']['value'] = $t('Installed');
  if (feeds_jsonpath_parser_load_library() === FALSE) {
    $message = '';

    // Lets make sure they know about the security issue here too, just in case
    // they got by without running updates.
    if (module_exists('libraries') && file_exists(libraries_get_path('jsonpath') . '/jsonpath.php')) {
      $message = $t('To remain secure because of issues identified in <a href="https://www.drupal.org/sa-contrib-2019-083">SA-CONTRIB-2019-083</a>, you must remove goessner/jsonpath and replace it with flow/jsonpath.');
    }
    if ($phase === 'runtime' || module_exists('libraries') && !file_exists(libraries_get_path('jsonpath') . '/src/Flow/JSONPath/JSONPath.php')) {
      $requirements['feeds_jsonpath_parser']['severity'] = REQUIREMENT_ERROR;
      $requirements['feeds_jsonpath_parser']['description'] = $message . ' ' . $t('The <a href="@jsonpath">JSONPath</a> library is missing. Download <a href="@download">@download</a> and place the contents of JSONPath-@version in sites/all/libraries/jsonpath and enable the modules "libraries" and "xautoload".', array(
        '@jsonpath' => 'https://github.com/FlowCommunications/JSONPath',
        '@version' => FEEDS_JSONPATH_PARSER_LIBRARY_VERSION,
        '@download' => 'https://github.com/FlowCommunications/JSONPath/archive/' . FEEDS_JSONPATH_PARSER_LIBRARY_VERSION . '.tar.gz',
      ));
      $requirements['feeds_jsonpath_parser']['value'] = $t('Not installed');
    }
  }
  if ($phase === 'install') {
    unset($requirements['feeds_jsonpath_parser']['value']);
  }
  return $requirements;
}

/**
 * Enable Xautoload as it's required for the new library.
 */
function feeds_jsonpath_parser_update_7001() {
  $t = get_t();
  if (!module_enable(array(
    'xautoload',
  ))) {
    throw new DrupalUpdateException("The module 'xautoload' couldn't be installed. Please download it.");
  }

  // Interesting edge case here. If you are using drush updb, and drush is
  // provided by composer, and you have flow/jsonpath installed, but you don't
  // have composer_autoload installed... or include vendor/autoload.php
  // elsewhere, class_exists() still returns TRUE because drush runs
  // vendor/autoload.php which allows this namespace to exist. However, this
  // namespace would still not exist on the Drupal website because it never
  // loads vendor/autoload.php.
  if (!class_exists('\\Flow\\JSONPath\\JSONPath', TRUE)) {

    // If not, then we should have libraries installed.
    if (!module_enable(array(
      'libraries',
    ))) {
      throw new DrupalUpdateException("You are not loading flow/jsonpath using composer and libraries couldn't be installed. Please download the libraries module or ensure flow/jsonpath is being loaded via your composer setup.");
    }
    if (!file_exists(libraries_get_path('jsonpath') . '/src/Flow/JSONPath/JSONPath.php')) {
      $message = '';

      // Lets make sure they know about the security issue.
      if (file_exists(libraries_get_path('jsonpath') . '/jsonpath.php')) {
        $message = $t('To remain secure because of issues identified in <a href="https://www.drupal.org/sa-contrib-2019-083">SA-CONTRIB-2019-083</a>, you must remove goessner/jsonpath and replace it with flow/jsonpath.');
      }
      $message .= ' ' . $t('The <a href="@jsonpath">JSONPath</a> library is missing. Download <a href="@download">@download</a> and place the contents of JSONPath-@version in sites/all/libraries/jsonpath', array(
        '@jsonpath' => 'https://github.com/FlowCommunications/JSONPath',
        '@version' => FEEDS_JSONPATH_PARSER_LIBRARY_VERSION,
        '@download' => 'https://github.com/FlowCommunications/JSONPath/archive/' . FEEDS_JSONPATH_PARSER_LIBRARY_VERSION . '.tar.gz',
      ));
      throw new DrupalUpdateException($message);
    }
  }
}

Functions

Namesort descending Description
feeds_jsonpath_parser_requirements Implements hook_requirements().
feeds_jsonpath_parser_update_7001 Enable Xautoload as it's required for the new library.