Skip to content

Instantly share code, notes, and snippets.

@arpitr
Last active May 16, 2018 20:46
Show Gist options
  • Save arpitr/0fdcc96208e88aa2fd39c93cb8682205 to your computer and use it in GitHub Desktop.
Save arpitr/0fdcc96208e88aa2fd39c93cb8682205 to your computer and use it in GitHub Desktop.
<?php
/**
* Perform: Create URL Alias for articles and Delete duplicate aliases;
*
* Code with in Migrate Plugin
* Run it year wise
* Get <url> from xml
* Can we get <nid>? use #1 : #2
*/
// #1. Key could be <node/nid> against source column
// #2. Or it could be <url> in xml against alias column
$query = db_merge('url_alias')
->key(array('source' => '/node/17326'))
->fields(array(
'source' => '/node/17326',
'alias' => '/article/alias/udpate-1', // map updated url alias here from xml <url field> + web-title/title
'langcode' => 'en',
));
$status = $query->execute();
// Maintain logs
if($status == 1) {
// Log a new term has been added to log file alias_generate.txt
} elseif($status == 2) {
// Log an existing term has been update to log file alias_update.txt
} else {
// Log unkown
}
// Delete duplicate url alias
$sql = 'delete ua from url_alias ua inner join url_alias ua2 where ua.pid < ua2.pid AND ua.source=ua2.source';
db_query($sql);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment