class DbReplacer in Convert Media Tags to Markup 8
Same name and namespace in other branches
- 2.x src/ConvertMediaTagsToMarkup/DbReplacer.php \Drupal\convert_media_tags_to_markup\ConvertMediaTagsToMarkup\DbReplacer
Code to replace all code in the database.
Hierarchy
- class \Drupal\convert_media_tags_to_markup\ConvertMediaTagsToMarkup\DbReplacer uses CommonUtilities, Singleton
Expanded class hierarchy of DbReplacer
File
- src/
ConvertMediaTagsToMarkup/ DbReplacer.php, line 11
Namespace
Drupal\convert_media_tags_to_markup\ConvertMediaTagsToMarkupView source
class DbReplacer {
use Singleton;
use CommonUtilities;
/**
* Log an error.
*
* @param string $err
* An error message.
* @param string $log
* A log function, for example 'print_r' or 'dpm'.
*/
protected function err(string $err, $log = 'print_r') {
$log('An error occurred: ' . $err . PHP_EOL);
$this->err = TRUE;
}
/**
* Replace all instances of legacy media tags in the database to images.
*
* Outputs the results using print_r(). This is designed to be used via
* drush.
*
* @param string $type
* A type such as node.
* @param string $bundle
* A bundle such as article.
* @param bool $simulate
* Whether or not to Simulate the results.
* @param string $log
* For example "print_r" or "dpm".
*/
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);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommonUtilities:: |
public | function | Mockable wrapper around decodeEntities(). | |
CommonUtilities:: |
public | function | Mockable wrapper around Json::decode(). | |
CommonUtilities:: |
public | function | Mockable wrapper around File::load(). Also throws an exception. | |
CommonUtilities:: |
protected | function | Get all entities of a specific type and bundle. | |
CommonUtilities:: |
public | function | Log a string to the watchdog. | |
CommonUtilities:: |
public | function | Log an error to the watchdog. | |
CommonUtilities:: |
public | function | Log a \Throwable to the watchdog. | |
DbReplacer:: |
protected | function | Log an error. | |
DbReplacer:: |
public | function | Replace all instances of legacy media tags in the database to images. | |
Singleton:: |
private static | property | Interal instance variable used with the instance() method. | |
Singleton:: |
public static | function | Implements the Singleton design pattern. |