Flatnux CMS

Open Source Content Management System

Login



 stay connected
Password recovery
Register

Search

Search:
Make a donation to the project:

Newsletter

To get our newsletter please enter your email and click on ”subscribe”. If you want to cancel the newsletter please enter your email and click on ”remove”

Forum->Flatnux->Cambio chiave primaria tabella user
  
Welcome Unknown Register Help383 Users

User Message


boymix81

0 Level 0 10

levellevellevellevellevellevellevellevellevellevel
profile  home
Tuesday 24 April 2007 - 23:51

Cambio chiave primaria tabella user:
Ciao,

ho avuto l'esigenza di cambiare la chiave primaria della tabella user, cambiando la struttura del file user.php , il tutto continua a funzionare tranne che per gli utenti vecchi.

La soluzione è spostare il nuovo campo chiave primaria ( gia' esistente per gli utenti vecchi ) come primo campo nel file dell'utente stesso.

Esiste già qualche funzione simile nel core di FN3 ? Qualcuno sa consigliarmi qualche funzione per manipolare i file utenti ( xml ) per creare una procedura che in base alla struttura del file user.php aggiorna i file utenti vecchi ?

Grazie, Boymix !

---
Per quanto nascosta essa sia a tutto c'è una spiegazione..



speleoalex

0 Level 10 10

levellevellevellevellevellevellevellevellevellevel
profile mail
Thursday 26 April 2007 - 09:08

Re: Cambio chiave primaria tabella user:
Bisognerebbe modificare xmldb.php affinchè non ci sia la limitazione della chiave primaria come primo campo ...
Per farlo occorre dare un po' di prove con le espressioni regolari.
I problemi si hanno a causa della funzione UpdateRecordBypk nel punto:

$newfilestring = preg_replace('/<' . $tablename . '>([^(' . $tablename . ')]*)<' . $pkey . '>' . $pvalue . '<\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/' . $pkey . '>(.*?)<\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/' . $tablename . '>/s', $strnew, $oldfilestring);


Alesandro



boymix81

0 Level 0 10

levellevellevellevellevellevellevellevellevellevel
profile  home
Thursday 26 April 2007 - 22:35

Re: Cambio chiave primaria tabella user:
Ciao forse ho risolto sostituendo in questo modo la regex:

$newfilestring = preg_replace('/<' . $tablename . '>(.*?)<' . $pkey . '>' . $pvalue . '<\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/' . $pkey . '>(.*?)<\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/' . $tablename . '>/s', $strnew, $oldfilestring);

Nel tuo caso il pattern di ricerca ( sostituito cn i valori) risultava:

/<users>([^(users)]*)<rnd>1424495395<\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/rnd>(.*?)<\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/users>/s

nel mio caso la chiave primaria è rnd, quindi cercavi tutto cio' che era dentro <users>*</users> MA CON chiave primaria preceduto da ([^(users)]*) ... nel mio caso prima non c'era nessun campo di questo tipo.

Con la nuova espressione ricerca in:
/<users>(.*?)<rnd>1424495395<\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/rnd>(.*?)<\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/users>/s

cioè ...
<users>*CHIAVE*</users>

secondo te puo' avere senso ? Comunque ora aggiorna, faccio ancora qualche prova.

Ciao..
Boymix !

---
Per quanto nascosta essa sia a tutto c'è una spiegazione..



speleoalex

0 Level 10 10

levellevellevellevellevellevellevellevellevellevel
profile mail
Friday 27 April 2007 - 08:15

Re: Cambio chiave primaria tabella user:
Ottimo, occorre però fare un po' di prove sia con tabelle multifile che monofile ...


Alex

 [1]

Last news