X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FFunctions%2FFunctionCallModifier.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FFunctions%2FFunctionCallModifier.php;h=b53e0b261f1eb631ec0c0f22999be1929de6e261;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Functions/FunctionCallModifier.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Functions/FunctionCallModifier.php new file mode 100644 index 000000000..b53e0b261 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Functions/FunctionCallModifier.php @@ -0,0 +1,76 @@ +pluginDefinition['function'] ?: $this->getPluginId()); + return $target->getIndexer('function_call')->has($function); + } + + /** + * {@inheritdoc} + */ + public function convert(TargetInterface $target) { + // Prevent stupid effing 'undefined index' notices. + $function = @($this->pluginDefinition['function'] ?: $this->getPluginId()); + + $function_calls = $target + ->getIndexer('function_call') + ->get($function); + + foreach ($function_calls as $function_call) { + // If the function call is no longer attached to a tree, don't even + // try to rewrite it. This could happen when there are two calls to + // the same function in a single statement, and the first one has + // been commented out -- the second one will be attached to an orphaned + // sub-tree, and this will result in fatal errors. + if (! $function_call->hasRoot()) { + continue; + } + + $rewritten = $this->rewrite($function_call, $target); + if (empty($rewritten)) { + $statement = $function_call->getStatement(); + $rewritten = $statement->toComment(); + $statement->replaceWith($rewritten); + $this->buildFixMe()->insertBefore($rewritten); + } + elseif ($rewritten !== $function_call) { + $function_call->replaceWith($rewritten); + } + + $target->save($rewritten); + } + } + +}