Commit ffd90827 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3267287 by nkoporec, heddn, pradeepjha, S_Bhandari, Berdir, daniel.bosen: [crop] Drupal 10

parent e15fe034
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8,6 +8,6 @@
  },
  "license": "GPL-2.0-or-later",
  "require": {
    "drupal/core": "^8.8 || ^9"
    "drupal/core": "^9.3 || ^10"
  }
}
+1 −1
Original line number Diff line number Diff line
name: Crop API
description: 'Provides storage and API for image crops.'
core_version_requirement: '^8.8 || ^9'
core_version_requirement: '^9.3 || ^10'
package: Media
type: module
dependencies:
+3 −74
Original line number Diff line number Diff line
@@ -5,9 +5,6 @@
 * Install, update and uninstall functions for the Crop API module.
 */

use Drupal\crop\CropStorageSchema;
use Drupal\crop\Entity\Crop;

/**
 * Implements hook_requirements().
 */
@@ -36,76 +33,8 @@ function crop_requirements($phase) {
}

/**
 * Delete orphaned crop entities.
 */
function crop_update_8001(&$sandbox) {
  // Unsure we have current element set to 0.
  if (!isset($sandbox['current'])) {
    $sandbox['current'] = 0;
    $sandbox['total'] = \Drupal::entityQuery('crop')
      ->count()
      ->execute();
  }

  $items_per_batch = 100;
  $crops = \Drupal::entityQuery('crop')
    ->sort('cid', 'ASC')
    ->range($sandbox['current'], $items_per_batch)
    ->execute();

  if (empty($crops)) {
    $sandbox['#finished'] = 1;
  }
  else {
    foreach ($crops as $cid) {
      /** @var \Drupal\crop\Entity\Crop $crop */
      $crop = Crop::load($cid);
      $files = \Drupal::entityQuery('file')
        ->condition('uri', $crop->get('uri')->value)
        ->count();

      // Checks if the file exist, if not exist delete this orphan crop.
      if (empty($files->execute())) {
        // Lets tell the site admin what we are doing.
        \Drupal::logger('crop_api')
          ->notice(
            'The orphaned crop @cid referring to image with URI @uri has been deleted.',
            ['@cid' => $cid, 'uri' => $crop->uri->value]
          );
        $crop->delete();
      }
      $sandbox['current']++;
    }
    $sandbox['#finished'] = $sandbox['current'] / $sandbox['total'];
  }
}

/**
 * Let Drupal know that there is a new config available.
 */
function crop_update_8002() {
  \Drupal::service('config.installer')
    ->installDefaultConfig('module', 'crop');
}

/**
 * Uninstall deprecated sub-module from active instance.
 */
function crop_update_8004() {
  if (\Drupal::moduleHandler()->moduleExists('crop_media_entity')) {
    \Drupal::service('module_installer')->uninstall(['crop_media_entity']);
  }
}

/**
 * Add index on type and uri.
 * Implements hook_update_last_removed().
 */
function crop_update_8005() {
  $manager = \Drupal::entityDefinitionUpdateManager();
  // Get the current crop entity type definition, ensure the storage schema
  // class is set.
  $entity_type = $manager->getEntityType('crop')
    ->setHandlerClass('storage_schema', CropStorageSchema::class);
  // Regenerate entity type indexes.
  $manager->updateEntityType($entity_type);
function crop_update_last_removed() {
  return 8005;
}
+1 −1
Original line number Diff line number Diff line
name: Media entity crop
description: 'Deprecated.'
core_version_requirement: '^8.7.7 || ^9'
core_version_requirement: '^9.3 || ^10'
package: Media
type: module
hidden: true
+1 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ class CropTypeListBuilder extends ConfigEntityListBuilder {
    // Load all image styles used by the current crop type.
    $image_style_ids = $this->entityTypeManager->getStorage('image_style')->getQuery()
      ->condition('effects.*.data.crop_type', $entity->id())
      ->accessCheck(TRUE)
      ->execute();
    $image_styles = ImageStyle::loadMultiple($image_style_ids);

Loading