From: olivier Date: Mon, 16 Jun 2008 19:14:33 +0000 (+0000) Subject: raw conversion: X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=2dc2e72eb5d42ce6a2edaa54726692e54b5fecaa;p=telemeta-data.git raw conversion: - writing README in french - added 4D script to export all tables at once - merged all 4D scripts into export.4d.txt - added mysql import bash script git-svn-id: http://svn.parisson.org/svn/crem@29 3bf09e05-f825-4182-b9bc-eedd7160adf0 --- diff --git a/import/raw_conversion/README b/import/raw_conversion/README index ddbf038..2ea95be 100644 --- a/import/raw_conversion/README +++ b/import/raw_conversion/README @@ -1,34 +1,42 @@ -========================================= -CREM database: 4D to MySQL raw conversion -========================================= +========================================================== +Base de données du CREM : conversion brut de 4D vers MySQL +========================================================== -Instructions and scripts to perform a full raw conversion of the CREM -database from 4D to MySQL. The result has the same structure as the -original 4D database, and, as such, can't be used directly in -Telemeta. +Le présent document décrit la procédure de conversion brut de la base de +données du CREM de 4D vers MySQL. La base MySQL obtenue a la même structure +que la base originale 4D. -Exporting the 4D database to text files ---------------------------------------- +Cette procédure doit être effectuée par un informaticien. -These instructions are for 4D 6.5.x on Windows. It should be possible to do this on -the Mac version too, with a few modifications. Warning: do this on a copy of the 4D -database, not on the production one. +Les instructions ci-dessous nécessitent l'emploi de la version 6.5.x de 4D pour +Windows. -1. Export all tables (all fields, all records) to windows "Text" - files, **with column titles**, using the 4D export dialogs. The resulting - files must named as the table with .txt as extension (ex: ``Support.txt``) +Avertissement: il est fortement recommandé de réaliser ces opérations sur une +copie de la base 4D, et non sur la version de production. -2. Create a new 4D method using the code provided in ``export_formations_4d.txt`` - and run it in order to export many-to-many instruments/performances relations - to ``C:\Formation.txt`` +1. Sur un poste Windows où se trouve la base du CREM, et équipé de 4D 6.5.x, + créer le répertoire C:\export_crem - Side note: if you're using a demo version of 4D you can't create a new method. - Just replace an existing method in this case. +2. Lancer 4D, ouvrir la base du CREM, créer une nouvelle méthode 4D avec + le code source fourni dans le fichier ``export.4d.txt``, et lancer cette + méthode de façon à exporter toute la base et les relations dans le + répertoire C:\export_crem -3. Create a new 4D method using the code provided in - ``export_fonction_usage_4d.txt`` and run it in order to export many-to-many - keywords relations to ``C:\Fonction_Usage.txt`` + Cette opération peut prendre plusieurs minutes. Une fenêtre "Export terminé" + s'affiche à la fin. + Remarque: si vous utilisez une version de démonstration de 4D, vous ne pouvez + pas créer de nouvelle méthode, mais vous pouvez remplacer une méthode existante. + +3. Placer le répertoire export_crem sur un poste linux, de façon à ce qu'il soit + accessible à l'import MySQL, par exemple dans /tmp/export_crem avec 777 pour + permissions +4. Créer une base MySQL, par exemple: crem +5. Importer la toutes les données dans la base MySQL avec la commande:: + ./import /tmp/export_crem | mysql -vvv crem + + Vérifiez que chaque requête se termine par "Query OK" avec "Warnings: 0", + pour vous assurer du bon déroulement de l'opération. diff --git a/import/raw_conversion/export.4d.txt b/import/raw_conversion/export.4d.txt new file mode 100755 index 0000000..4f7beff --- /dev/null +++ b/import/raw_conversion/export.4d.txt @@ -0,0 +1,179 @@ +`Export de toutes les tables + +C_ALPHA(1;$fieldDelimiter;$recordDelimiter) +C_ALPHA(32;$tableName;$fieldName) +C_ENTIER LONG($numberOfTables;$tableNumber;$numberOfFields;$fieldNumber) +C_ENTIER LONG($numberOfRecords;$fieldType) +C_POINTEUR($tablePtr;$fieldPtr) +C_TEXTE($fieldValue) +C_HEURE($documentReference) +C_REEL($Plateforme) +PROPRIETES PLATE FORME($Plateforme) + +$fieldDelimiter:=Caractere(9)   +$recordDelimiter:=Caractere(10)   + +$numberOfTables:=Nombre de tables   + +Boucle ($tableNumber;1;$numberOfTables)   + + $tablePtr:=Table($tableNumber)   + $tableName:=Nom de la table($tableNumber)   + + $documentReference:=Creer document("C:\export_crem\"+$tableName+".txt";"TEXT")   + + Si (OK=1)   + $numberOfFields:=Nombre de champs($tableNumber)   + + Boucle ($fieldNumber;1;$numberOfFields)   + $fieldName:=Nom du champ($tableNumber;$fieldNumber)   + Si ($fieldNumber#$numberOfFields)   + Si ($Plateforme=Windows ) + ENVOYER PAQUET($documentReference;Mac vers Windows($fieldName)+$fieldDelimiter) +    + Sinon + ENVOYER PAQUET($documentReference;$fieldName+$fieldDelimiter) +    + Fin de si + Sinon + Si ($plateforme=Windows ) + ENVOYER PAQUET($documentReference;Mac vers Windows($fieldName)+$recordDelimiter) +    + Sinon + ENVOYER PAQUET($documentReference;$fieldName+$recordDelimiter) +    + Fin de si + Fin de si + Fin de boucle + + TOUT SELECTIONNER($tablePtr->)   + $numberOfRecords:=Enregistrements trouves($tablePtr->)   + + Boucle ($recordNumber;1;$numberOfRecords)   + + Boucle ($fieldNumber;1;$numberOfFields)   + + $fieldPtr:=Champ($tableNumber;$fieldNumber)   + PROPRIETES CHAMP($fieldPtr;$fieldType)   + +    + + Au cas ou + : (($fieldType=Est un numérique ) | ($fieldType=Est un entier ) | ($fieldType=Est un entier long )) + $fieldValue:=Chaine($fieldPtr->)   + : ($fieldType=Est une date ) + $fieldValue:=Chaine($fieldPtr->;7)   + : ($fieldType=Est une heure ) + $fieldValue:=Chaine($fieldPtr->;1)   + : ($fieldType=Est un booléen ) + +    + + $fieldValue:=Chaine(Num($fieldPtr->);"VRAI;;FAUX")   + : ($fieldType=Est une image ) + $fieldValue:="Image non exportée" + : ($fieldType=Est un BLOB ) + $fieldValue:="BLOB non exporté" + : ($fieldType=Est une sous table ) + $fieldValue:="Sous-table non exportée" + Sinon    + $fieldValue:=$fieldPtr->   + $fieldValue:=Remplacer chaine ($fieldValue; $fieldDelimiter; " ") + $fieldValue:=Remplacer chaine ($fieldValue; $recordDelimiter; " ") + Fin de cas + + Si ($fieldNumber#$numberOfFields)   + Si ($Plateforme=Windows ) + ENVOYER PAQUET($documentReference;Mac vers Windows($fieldValue)+$fieldDelimiter)   + Sinon + ENVOYER PAQUET($documentReference;$fieldValue+$fieldDelimiter)   + Fin de si + Sinon + Si ($Plateforme=Windows ) + ENVOYER PAQUET($documentReference;Mac vers Windows($fieldValue)+$recordDelimiter)   +    + Sinon + ENVOYER PAQUET($documentReference;$fieldValue+$recordDelimiter)   +    + Fin de si + + Fin de si + + Fin de boucle + + ENREGISTREMENT SUIVANT($tablePtr->)   + Fin de boucle + + FERMER DOCUMENT($documentReference)   + CHANGER CREATEUR DOCUMENT(Document;"TEXT") + + Fin de si + +Fin de boucle + +`Export des relations des formations + +$doc:=Creer document("c:\export_crem\Formation.txt";"TXT") +Si (ok=1) + $tab:=Caractere(9) + $fin:=Caractere(10) + $texte:="Cote_Phono"+$tab+"Instr_Scientif"+$tab+"Instr_Vernacul"+$tab+"Interprète"+$tab+"Total_Instrum"+$fin + ENVOYER PAQUET($doc;Mac vers Windows($texte)) + TOUT SELECTIONNER([Phono]) + Boucle ($i;1;Enregistrements trouves([Phono])) + $cote:=[Phono]Cote_Phono + $cote:=Remplacer chaine($cote; $tab; " ") + $cote:=Remplacer chaine($cote; $fin; " ") + TOUS LES SOUS ENREGISTREMENTS([Phono]Formation) + Boucle ($j;1;Sous enregistrements trouves([Phono]Formation) + $instr_scientif:=Remplacer chaine([Phono]Formation'Instr_Scientif; $tab; " ") + $instr_scientif:=Remplacer chaine($instr_scientif; $fin; " ") + $instr_vernacul:=Remplacer chaine([Phono]Formation'Instr_Vernacul; $tab; " ") + $instr_vernacul:=Remplacer chaine($instr_vernacul; $fin; " ") + $interprete:=Remplacer chaine([Phono]Formation'Interprète; $tab; " ") + $interprete:=Remplacer chaine($interprete; $fin; " ") + $total:=Remplacer chaine([Phono]Formation'Total_Instrum; $tab; " ") + $total:=Remplacer chaine($total; $fin; " ") + $texte:=$cote+$tab+$instr_scientif+$tab+$instr_vernacul+$tab+$interprete+$tab+$total+$fin + ENVOYER PAQUET($doc;Mac vers Windows($texte)) + SOUS ENREGISTREMENT SUIVANT([Phono]Formation) + Fin de boucle + LIBERER ENREGISTREMENT([Phono]) + ENREGISTREMENT SUIVANT([Phono]) + Fin de boucle + + FERMER DOCUMENT($doc) + +Fin de si + +`Export des relations des mots clés + +$doc:=Creer document("c:\export_crem\Fonction_Usage.txt";"TXT") +Si (ok=1) + $tab:=Caractere(9) + $fin:=Caractere(10) + $texte:="Cote_Phono"+$tab+"Mot_Clef"+$fin + ENVOYER PAQUET($doc;Mac vers Windows($texte)) + TOUT SELECTIONNER([Phono]) + Boucle ($i;1;Enregistrements trouves([Phono])) + $cote:=[Phono]Cote_Phono + $cote:=Remplacer chaine($cote; $tab; " ") + $cote:=Remplacer chaine($cote; $fin; " ") + TOUS LES SOUS ENREGISTREMENTS([Phono]Fonction_Usage) + Boucle ($j;1;Sous enregistrements trouves([Phono]Fonction_Usage) + $mot_clef:=Remplacer chaine([Phono]Fonction_Usage'Mot_Clef; $tab; " ") + $mot_clef:=Remplacer chaine($mot_clef; $fin; " ") + $texte:=$cote+$tab+$mot_clef+$fin + ENVOYER PAQUET($doc;Mac vers Windows($texte)) + SOUS ENREGISTREMENT SUIVANT([Phono]Fonction_Usage) + Fin de boucle + LIBERER ENREGISTREMENT([Phono]) + ENREGISTREMENT SUIVANT([Phono]) + Fin de boucle + + FERMER DOCUMENT($doc) + +Fin de si + + +ALERTE("Export terminé.") diff --git a/import/raw_conversion/export_fonction_usage_4d.txt b/import/raw_conversion/export_fonction_usage_4d.txt deleted file mode 100644 index de097e0..0000000 --- a/import/raw_conversion/export_fonction_usage_4d.txt +++ /dev/null @@ -1,22 +0,0 @@ - -$doc:=Creer document("c:\Fonction_Usage.txt";"TXT") -Si (ok=1) - $tab:=Caractere(9) - $fin:=Caractere(13) - TOUT SELECTIONNER([Phono]) - Boucle ($i;1;Enregistrements trouves([Phono])) - $cote:=[Phono]Cote_Phono - TOUS LES SOUS ENREGISTREMENTS([Phono]Fonction_Usage) - Boucle ($j;1;Sous enregistrements trouves([Phono]Fonction_Usage) - $texte:=$cote+$tab+[Phono]Fonction_Usage'Mot_Clef+$fin - ENVOYER PAQUET($doc;Mac vers Windows($texte)) - SOUS ENREGISTREMENT SUIVANT([Phono]Fonction_Usage) - Fin de boucle - LIBERER ENREGISTREMENT([Phono]) - ENREGISTREMENT SUIVANT([Phono]) - Fin de boucle - - FERMER DOCUMENT($doc) - -Fin de si - diff --git a/import/raw_conversion/export_formations_4d.txt b/import/raw_conversion/export_formations_4d.txt deleted file mode 100644 index 68f73cb..0000000 --- a/import/raw_conversion/export_formations_4d.txt +++ /dev/null @@ -1,22 +0,0 @@ - -$doc:=Creer document("c:\Formation.txt";"TXT") -Si (ok=1) - $tab:=Caractere(9) - $fin:=Caractere(13) - TOUT SELECTIONNER([Phono]) - Boucle ($i;1;Enregistrements trouves([Phono])) - $cote:=[Phono]Cote_Phono - TOUS LES SOUS ENREGISTREMENTS([Phono]Formation) - Boucle ($j;1;Sous enregistrements trouves([Phono]Formation) - $texte:=$cote+$tab+[Phono]Formation'Instr_Scientif+$tab+[Phono]Formation'Instr_Vernacul+$tab+[Phono]Formation'Interpr?te+$tab+[Phono]Formation'Total_Instrum+$fin - ENVOYER PAQUET($doc;Mac vers Windows($texte)) - SOUS ENREGISTREMENT SUIVANT([Phono]Formation) - Fin de boucle - LIBERER ENREGISTREMENT([Phono]) - ENREGISTREMENT SUIVANT([Phono]) - Fin de boucle - - FERMER DOCUMENT($doc) - -Fin de si - diff --git a/import/raw_conversion/import b/import/raw_conversion/import new file mode 100755 index 0000000..cdfb1c3 --- /dev/null +++ b/import/raw_conversion/import @@ -0,0 +1,50 @@ +#!/bin/bash + +function extract_enum +{ + to_table=$1 + from_table=$2 + from_field=$3 + echo "DROP TABLE IF EXISTS \`$to_table\`;" + echo "CREATE TABLE \`$to_table\` (value TEXT NOT NULL) CHARSET=latin1;" + echo "INSERT INTO \`$to_table\` SELECT \`$from_field\` FROM \`$from_table\`;"; +} + +src=$1 +cd $src + +echo "SET NAMES 'latin1';" +echo + +chmod o+r *.txt + +ls *.txt | while read filename +do + table=$(echo $filename | sed 's/.txt//') + echo "DROP TABLE IF EXISTS \`$table\`;" + echo "CREATE TABLE \`$table\` (" + head -n1 $filename | tr '\t' '\n' | head -n-1 | sed 's/^/ `/' | sed 's/$/` TEXT NOT NULL,/' + head -n1 $filename | tr '\t' '\n' | tail -n1 | sed 's/^/ `/' | sed 's/$/` TEXT NOT NULL/' + echo ") CHARSET=latin1;" + echo + echo "LOAD DATA INFILE '$src/$filename'" + echo " INTO TABLE \`$table\`" + echo " CHARACTER SET 'latin1'" + echo " FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" + echo " IGNORE 1 LINES;" + echo "SHOW WARNINGS;" + echo +done + +extract_enum Format Support Format +extract_enum Réédition Support Réédition +extract_enum Mode_Acqui Support Mode_Acqui +extract_enum Rédacteur_Fiche Support Rédacteur_Fiche +extract_enum Saisie_Fiche Support Saisie_Fiche +extract_enum Droit_Utiliser Support Droit_Utiliser +extract_enum Terrain_ou_Autr Support Terrain_ou_Autr +extract_enum Numérisation Support Numérisation +extract_enum "FormStyl généri" Phono "FormStyl généri" +extract_enum Editeur1 Support Editeur +extract_enum Collection_Serie Support Collect_Série +