-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from City-of-Helsinki/SATT-34-Batch_process
SATT-34: Batch process
- Loading branch information
Showing
3 changed files
with
137 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Drupal\asu_content; | ||
|
||
/** | ||
* Batch service to update node aliases. | ||
*/ | ||
class BatchService { | ||
|
||
/** | ||
* Batch process callback. | ||
* | ||
* @param int $id | ||
* Id of the batch. | ||
* @param array $nodes | ||
* Nodes for batch. | ||
* @param object $context | ||
* Context for operations. | ||
*/ | ||
public static function processContentAliasUpdate($id, $nodes, &$context) { | ||
foreach ($nodes as $node) { | ||
usleep(100); | ||
$entityService = \Drupal::entityTypeManager(); | ||
$entity = $entityService->getStorage('node')->load($node->nid); | ||
|
||
if ($entity) { | ||
/** @var \Drupal\node\Entity $entity */ | ||
$entity->path->pathauto = 1; | ||
$entity->save(); | ||
$context['results'][] = $id; | ||
$context['message'] = t('processing "@id"', | ||
['@id' => $id] | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Batch Finished callback. | ||
* | ||
* @param bool $success | ||
* Success of the operation. | ||
* @param array $results | ||
* Array of results for post processing. | ||
* @param array $operations | ||
* Array of operations. | ||
*/ | ||
public static function processContentAliasUpdateFinished($success, array $results, array $operations) { | ||
$messenger = \Drupal::messenger(); | ||
|
||
if ($success) { | ||
$messenger->addMessage(t('@count results processed.', ['@count' => count($results)])); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters