DbReplacer.php in Convert Media Tags to Markup 2.x
File
src/ConvertMediaTagsToMarkup/DbReplacer.php
View source
<?php
namespace Drupal\convert_media_tags_to_markup\ConvertMediaTagsToMarkup;
use Drupal\convert_media_tags_to_markup\traits\Singleton;
use Drupal\convert_media_tags_to_markup\traits\CommonUtilities;
class DbReplacer {
use Singleton;
use CommonUtilities;
protected function err(string $err, $log = 'print_r') {
$log('An error occurred: ' . $err . PHP_EOL);
$this->err = TRUE;
}
public function replaceAll(string $type, string $bundle, bool $simulate = TRUE, string $log = 'print_r') {
try {
foreach ($this
->getAllEntities($type, $bundle) as $entity) {
try {
$entity
->process($simulate, $log);
} catch (\Throwable $t) {
$this
->err($t
->getMessage(), $log);
}
}
} catch (\Throwable $t) {
$this
->err($t
->getMessage() . ' at ' . $t
->getFile() . ':' . $t
->getLine(), $log);
}
if (!empty($this->err)) {
$log('Exiting with error code 1 because at least one error occurred during processing.' . PHP_EOL);
exit(1);
}
}
}