Beispiel #1
0
<?php

/**
 * @file update_aliases.php
 *
 * Drush script for removing the prefixed / from the courses aliases.
 *
 * @example:
 *
 *   drush scr update_aliases.php
 */
if (!drupal_is_cli()) {
    // The file is not reachable via web browser.
    return;
}
// Iterate over the elements.
$results = db_select('url_alias', 'u')->fields('u', array('pid'))->condition('alias', '/courses%', 'LIKE')->execute()->fetchAllAssoc('pid');
if (!$results) {
    return;
}
foreach (array_keys($results) as $pid) {
    $path = path_load(array('pid' => $pid));
    $params['@url'] = $path['alias'];
    $path['alias'] = str_replace('/courses', 'courses', $path['alias']);
    path_save($path);
    $sandbox['pid'] = $params['@pid'] = $path['pid'];
    drush_log(dt('Updating @url(@pid)', $params), 'success');
}
    $info = explode('/', $result->source);
    $purl = os_taxonomy_vsite_path(end($info));
    if (!$purl) {
        // The vsite the vocab relate to don't have a purl. Return.
        continue;
    }
    if (strpos($result->alias, $purl) !== FALSE) {
        // The term already have the purl at the start of the alias. Return.
        continue;
    }
    $alias = $purl . '/' . $result->alias;
    $new_path = (array) $result + array('alias' => $alias);
    $params = array('@alias' => $result->alias, '@new-alias' => $alias);
    // Update the alias and display a nice message.
    drush_log(dt('The alias @alias has been updated to @new-alias', $params), 'success');
    path_save($new_path);
}
/**
 * Get the path of the vsite which the vocab belong.
 *
 * @param $tid
 *  The term ID.
 *
 * @return
 *  The path of the vsite.
 */
function os_taxonomy_vsite_path($tid)
{
    $term = taxonomy_term_load($tid);
    $purls =& drupal_static(__FUNCTION__, array());
    if (in_array($term->vid, $purls)) {