Conjunto de cambios d7a822e en sipes para cord/modules/path/path.module
- Fecha y hora:
- 23/05/2016 15:48:25 (hace 8 años)
- Branches:
- stable, version-3.0
- Children:
- 6f9ddf1
- Parents:
- b354002
- Fichero:
-
- 1 editado
Leyenda
- No modificado
- Añadido
- Eliminado
-
cord/modules/path/path.module
rb354002 rd7a822e 84 84 /** 85 85 * Set an aliased path for a given Drupal path, preventing duplicates. 86 * 87 * @param $path 88 * Path URL. Set to NULL to delete alias. 89 * @param $alias 90 * Alias URL. Set to NULL to delete alias. 91 * @param $pid 92 * Path id to update. Set to NULL to create a new alias or to delete a group of aliases. 93 * @param $language 94 * The language this alias is valid for. 86 95 */ 87 96 function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '') { 97 /* This function claimed to prevent duplicate aliases but has not done 98 * so since the end of 2007. 99 * The uniqueness of dst+language pairs was enforced on the database level 100 * until D6.16 (march 2010); trying to insert duplicate aliass would yield a 101 * database error. 102 * From D6.16 onwards, duplicates would silently be inserted, and 103 * drupal_lookup_path() consistently uses those newer aliases. 104 * While fixing an issue in D6.23, the behavior was reverted to preventing 105 * duplicates by the below code. Watchdog errors are now logged instead. 106 */ 88 107 $path = urldecode($path); 89 108 $alias = urldecode($alias); … … 97 116 else { 98 117 // Update the existing alias. 99 db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE pid = %d", $path, $alias, $language, $pid); 100 } 101 } 102 else if ($path && $alias) { 103 // Check for existing aliases. 104 if ($alias == drupal_get_path_alias($path, $language)) { 105 // There is already such an alias, neutral or in this language. 106 // Update the alias based on alias; setting the language if not yet done. 107 db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE dst = '%s'", $path, $alias, $language, $alias); 108 } 109 else { 118 // Check if the alias exists already. 119 $existing = db_fetch_array(db_query("SELECT pid, src FROM {url_alias} WHERE dst = '%s' AND language = '%s' ORDER BY pid DESC", $alias, $language)); 120 if (!$existing || ($existing['pid'] == $pid && $existing['src'] != $path)) { 121 db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE pid = %d", $path, $alias, $language, $pid); 122 } 123 else { 124 if ($existing['src'] != $path) { 125 watchdog('path', "The alias for path '@path' (language '@lang') was not updated to '@alias', because the path '@expath' already has the same alias.", 126 array('@path' => $path, '@lang' => $language, '@alias' => $alias, '@expath' => $existing['src']), 127 WATCHDOG_ERROR); 128 } 129 // Don't clear cache if we didn't change anything 130 return; 131 } 132 } 133 } 134 elseif ($path && $alias) { 135 // Add this alias to the database, if it's new & doesn't cause conflicts. 136 $existing = db_fetch_array(db_query("SELECT src, language, pid FROM {url_alias} WHERE dst = '%s' AND language IN('%s', '') ORDER BY language DESC, pid DESC", $alias, $language)); 137 if (!$existing || ($existing['language'] != $language && $existing['src'] != $path)) { 110 138 // A new alias. Add it to the database. 111 139 db_query("INSERT INTO {url_alias} (src, dst, language) VALUES ('%s', '%s', '%s')", $path, $alias, $language); 140 } 141 elseif ($existing['language'] != $language) { 142 // This alias already exists ONLY for 'language neutral': update language. 143 // (We can only get here if $language != '') 144 db_query("UPDATE {url_alias} SET language = '%s' WHERE pid = %d", $language, $existing['pid']); 145 } 146 else { 147 if ($existing['src'] != $path) { 148 watchdog('path', "The alias '@alias' for path '@path' (language '@lang') was not created, because the path '@expath' already has the same alias.", 149 array('@path' => $path, '@lang' => $language, '@alias' => $alias, '@expath' => $existing['src']), 150 WATCHDOG_ERROR); 151 } 152 // Don't clear cache if we didn't change anything 153 return; 112 154 } 113 155 } … … 131 173 * than through the administrative interface. 132 174 */ 133 function path_nodeapi(&$node, $op, $arg ) {175 function path_nodeapi(&$node, $op, $arg = NULL) { 134 176 // Permissions are required for everything except node loading. 135 177 if (user_access('create url aliases') || user_access('administer url aliases') || ($op == 'load')) { … … 162 204 163 205 case 'update': 206 // $node->pid is usually only set when updating from a node edit form 207 // (see path_form_alter). If it is not set (e.g. on most node_save() 208 // commands), we cannot be sure whether a change in $node->path is meant 209 // to replace an existing alias or add one extra, so we do the latter. 164 210 path_set_alias('node/'. $node->nid, isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL, $language); 165 211 break;
Nota: Vea TracChangeset
para ayuda en el uso del visor de conjuntos de cambios.