-
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 #531 from City-of-Helsinki/develop
Release 20.3
- Loading branch information
Showing
5 changed files
with
142 additions
and
18 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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