Zatem skoro nikt nie spotkał się z tym problemem to trudno, musiałem sam opracować metodę aktualizacji przyjaznych adresów. To co jest kodem należy przenieść do jakiegoś pliku php i po prostu uruchomić. W kodzie jest założenie, że plik ten znajdzie się w jakimś katalogu na poziomie katalogu "classes" - poszukuje relatywnie pliku Tools.php.
link-rewrite.php
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="Update link-rewrite"');
header('HTTP/1.0 401 Unauthorized');
echo 'Executing script updating link-rewrite canceled';
exit;
}
//connect
$db_server = 'mysql_server';
$db_user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
//select & modify
$db_name = 'your_database';
$db_table_prefix = 'ps_';
$connection = @mysql_connect($db_server, $db_user, $pass)
or die('No connection with MySQL.<br />Error: '.mysql_error());
echo 'Connected to: '.$db_server.'<br />';
//select db where is Prestashop installed
$db = @mysql_select_db($db_name, $connection)
or die('Connection to: '.$db_name.'failed.<br />Error: '.mysql_error());
echo 'Connected to: '.$db_name.'<br>';
// correct the path to where the Tools.php is located
// this assumes link-rewrite.php is located in dir at the same level as classes
if (file_exists('../classes/Tools.php'))
{
include '../classes/Tools.php';
}
else
{
echo 'nie istnieje: '.'../classes/Tools.php';
}
$Tools = new ToolsCore;
$query = 'select * from '.$dbname.'.`'.$db_table_prefix.'product_lang`';
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
$id_product = $row['id_product'];
$name = $row['name'];
$old_link_rewrite = $row['link_rewrite'];
/*
echo 'link rewrite updating: ';
echo 'id_product: ['.$id_product.'] ';
echo 'name: '.$name.'; ';
echo 'old_link_rewrite: '.$old_link_rewrite.';<br>';
*/
// recreate link_rewrite based on product's name
$new_link_rewrite = $Tools->link_rewrite( $name);
//update all link_rewrite if there's no dash "-"
//dash condition aplies to my db so it can be removed
$query_update = sprintf("update %s.`%s"."product_lang` set link_rewrite = '%s'"
." where id_product =%s and (position('-' in `link_rewrite`) = 0)",
$db_name, $db_table_prefix, $new_link_rewrite, $id_product );
if (mysql_query($query_update))
{
echo 'link rewrite updated ok';
echo 'id_product: ['.$id_product.'] ';
echo 'name: '.$name.'; ';
echo 'new_link_rewrite: '.$new_link_rewrite.'; ';
echo 'old_link_rewrite: '.$old_link_rewrite.';<br>';
}
else
{
echo 'update failed for product: '.$id_product.'<br>';
}
}
//free select results
mysql_free_result($result);
// close connection
mysql_close($connection);
?>