]> git.parisson.com Git - telemeta-data.git/commitdiff
raw conversion:
authorolivier <olivier@3bf09e05-f825-4182-b9bc-eedd7160adf0>
Mon, 16 Jun 2008 19:14:33 +0000 (19:14 +0000)
committerolivier <olivier@3bf09e05-f825-4182-b9bc-eedd7160adf0>
Mon, 16 Jun 2008 19:14:33 +0000 (19:14 +0000)
- 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

import/raw_conversion/README
import/raw_conversion/export.4d.txt [new file with mode: 0755]
import/raw_conversion/export_fonction_usage_4d.txt [deleted file]
import/raw_conversion/export_formations_4d.txt [deleted file]
import/raw_conversion/import [new file with mode: 0755]

index ddbf038a75702453af8aff92a791f12910a59397..2ea95be1c561a17f3715abfd685bb481865fb02e 100644 (file)
@@ -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 (executable)
index 0000000..4f7beff
--- /dev/null
@@ -0,0 +1,179 @@
+`Export de toutes les tables\r
+\r
+C_ALPHA(1;$fieldDelimiter;$recordDelimiter)\r
+C_ALPHA(32;$tableName;$fieldName)\r
+C_ENTIER LONG($numberOfTables;$tableNumber;$numberOfFields;$fieldNumber)\r
+C_ENTIER LONG($numberOfRecords;$fieldType)\r
+C_POINTEUR($tablePtr;$fieldPtr)\r
+C_TEXTE($fieldValue)\r
+C_HEURE($documentReference)\r
+C_REEL($Plateforme)\r
+PROPRIETES PLATE FORME($Plateforme)\r
+\r
+$fieldDelimiter:=Caractere(9)  \r
+$recordDelimiter:=Caractere(10)  \r
+\r
+$numberOfTables:=Nombre de tables  \r
+\r
+Boucle ($tableNumber;1;$numberOfTables)  \r
+  \r
+  $tablePtr:=Table($tableNumber)  \r
+  $tableName:=Nom de la table($tableNumber)  \r
+  \r
+  $documentReference:=Creer document("C:\export_crem\"+$tableName+".txt";"TEXT")  \r
+  \r
+  Si (OK=1)  \r
+    $numberOfFields:=Nombre de champs($tableNumber)  \r
+    \r
+    Boucle ($fieldNumber;1;$numberOfFields)  \r
+      $fieldName:=Nom du champ($tableNumber;$fieldNumber)  \r
+      Si ($fieldNumber#$numberOfFields)  \r
+        Si ($Plateforme=Windows )\r
+          ENVOYER PAQUET($documentReference;Mac vers Windows($fieldName)+$fieldDelimiter)\r
+            \r
+        Sinon \r
+          ENVOYER PAQUET($documentReference;$fieldName+$fieldDelimiter)\r
+            \r
+        Fin de si \r
+      Sinon \r
+        Si ($plateforme=Windows )\r
+          ENVOYER PAQUET($documentReference;Mac vers Windows($fieldName)+$recordDelimiter)\r
+            \r
+        Sinon \r
+          ENVOYER PAQUET($documentReference;$fieldName+$recordDelimiter)\r
+            \r
+        Fin de si \r
+      Fin de si \r
+    Fin de boucle \r
+    \r
+    TOUT SELECTIONNER($tablePtr->)  \r
+    $numberOfRecords:=Enregistrements trouves($tablePtr->)  \r
+    \r
+    Boucle ($recordNumber;1;$numberOfRecords)  \r
+      \r
+      Boucle ($fieldNumber;1;$numberOfFields)  \r
+        \r
+        $fieldPtr:=Champ($tableNumber;$fieldNumber)  \r
+        PROPRIETES CHAMP($fieldPtr;$fieldType)  \r
+        \r
+          \r
+        \r
+        Au cas ou \r
+          : (($fieldType=Est un numérique ) | ($fieldType=Est un entier ) | ($fieldType=Est un entier long ))\r
+            $fieldValue:=Chaine($fieldPtr->)  \r
+          : ($fieldType=Est une date )\r
+            $fieldValue:=Chaine($fieldPtr->;7)  \r
+          : ($fieldType=Est une heure )\r
+            $fieldValue:=Chaine($fieldPtr->;1)  \r
+          : ($fieldType=Est un booléen )\r
+            \r
+              \r
+            \r
+            $fieldValue:=Chaine(Num($fieldPtr->);"VRAI;;FAUX")  \r
+          : ($fieldType=Est une image )\r
+            $fieldValue:="Image non exportée"\r
+          : ($fieldType=Est un BLOB )\r
+            $fieldValue:="BLOB non exporté"\r
+          : ($fieldType=Est une sous table )\r
+            $fieldValue:="Sous-table non exportée"\r
+          Sinon   \r
+            $fieldValue:=$fieldPtr->  \r
+            $fieldValue:=Remplacer chaine ($fieldValue; $fieldDelimiter; " ")\r
+            $fieldValue:=Remplacer chaine ($fieldValue; $recordDelimiter; " ")\r
+        Fin de cas \r
+        \r
+        Si ($fieldNumber#$numberOfFields)  \r
+          Si ($Plateforme=Windows )\r
+            ENVOYER PAQUET($documentReference;Mac vers Windows($fieldValue)+$fieldDelimiter)  \r
+          Sinon \r
+            ENVOYER PAQUET($documentReference;$fieldValue+$fieldDelimiter)  \r
+          Fin de si \r
+        Sinon \r
+          Si ($Plateforme=Windows )\r
+            ENVOYER PAQUET($documentReference;Mac vers Windows($fieldValue)+$recordDelimiter)  \r
+              \r
+          Sinon \r
+            ENVOYER PAQUET($documentReference;$fieldValue+$recordDelimiter)  \r
+              \r
+          Fin de si \r
+          \r
+        Fin de si \r
+        \r
+      Fin de boucle \r
+      \r
+      ENREGISTREMENT SUIVANT($tablePtr->)  \r
+    Fin de boucle \r
+    \r
+    FERMER DOCUMENT($documentReference)  \r
+    CHANGER CREATEUR DOCUMENT(Document;"TEXT")\r
+    \r
+  Fin de si \r
+  \r
+Fin de boucle \r
+\r
+`Export des relations des formations\r
+\r
+$doc:=Creer document("c:\export_crem\Formation.txt";"TXT")\r
+Si (ok=1)\r
+  $tab:=Caractere(9)\r
+  $fin:=Caractere(10)\r
+  $texte:="Cote_Phono"+$tab+"Instr_Scientif"+$tab+"Instr_Vernacul"+$tab+"Interprète"+$tab+"Total_Instrum"+$fin\r
+  ENVOYER PAQUET($doc;Mac vers Windows($texte))\r
+  TOUT SELECTIONNER([Phono])\r
+  Boucle ($i;1;Enregistrements trouves([Phono]))\r
+    $cote:=[Phono]Cote_Phono\r
+    $cote:=Remplacer chaine($cote; $tab; " ")\r
+    $cote:=Remplacer chaine($cote; $fin; " ")\r
+    TOUS LES SOUS ENREGISTREMENTS([Phono]Formation)\r
+    Boucle ($j;1;Sous enregistrements trouves([Phono]Formation)\r
+      $instr_scientif:=Remplacer chaine([Phono]Formation'Instr_Scientif; $tab; " ")\r
+      $instr_scientif:=Remplacer chaine($instr_scientif; $fin; " ")\r
+      $instr_vernacul:=Remplacer chaine([Phono]Formation'Instr_Vernacul; $tab; " ")\r
+      $instr_vernacul:=Remplacer chaine($instr_vernacul; $fin; " ")\r
+      $interprete:=Remplacer chaine([Phono]Formation'Interprète; $tab; " ")\r
+      $interprete:=Remplacer chaine($interprete; $fin; " ")\r
+      $total:=Remplacer chaine([Phono]Formation'Total_Instrum; $tab; " ")\r
+      $total:=Remplacer chaine($total; $fin; " ")\r
+      $texte:=$cote+$tab+$instr_scientif+$tab+$instr_vernacul+$tab+$interprete+$tab+$total+$fin\r
+      ENVOYER PAQUET($doc;Mac vers Windows($texte))\r
+      SOUS ENREGISTREMENT SUIVANT([Phono]Formation)\r
+    Fin de boucle \r
+    LIBERER ENREGISTREMENT([Phono])\r
+    ENREGISTREMENT SUIVANT([Phono])\r
+  Fin de boucle \r
+  \r
+  FERMER DOCUMENT($doc)\r
+  \r
+Fin de si \r
+\r
+`Export des relations des mots clés\r
+\r
+$doc:=Creer document("c:\export_crem\Fonction_Usage.txt";"TXT")\r
+Si (ok=1)\r
+  $tab:=Caractere(9)\r
+  $fin:=Caractere(10)\r
+  $texte:="Cote_Phono"+$tab+"Mot_Clef"+$fin\r
+  ENVOYER PAQUET($doc;Mac vers Windows($texte))\r
+  TOUT SELECTIONNER([Phono])\r
+  Boucle ($i;1;Enregistrements trouves([Phono]))\r
+    $cote:=[Phono]Cote_Phono\r
+    $cote:=Remplacer chaine($cote; $tab; " ")\r
+    $cote:=Remplacer chaine($cote; $fin; " ")\r
+    TOUS LES SOUS ENREGISTREMENTS([Phono]Fonction_Usage)\r
+    Boucle ($j;1;Sous enregistrements trouves([Phono]Fonction_Usage)\r
+      $mot_clef:=Remplacer chaine([Phono]Fonction_Usage'Mot_Clef; $tab; " ")\r
+      $mot_clef:=Remplacer chaine($mot_clef; $fin; " ")\r
+      $texte:=$cote+$tab+$mot_clef+$fin\r
+      ENVOYER PAQUET($doc;Mac vers Windows($texte))\r
+      SOUS ENREGISTREMENT SUIVANT([Phono]Fonction_Usage)\r
+    Fin de boucle \r
+    LIBERER ENREGISTREMENT([Phono])\r
+    ENREGISTREMENT SUIVANT([Phono])\r
+  Fin de boucle \r
+  \r
+  FERMER DOCUMENT($doc)\r
+  \r
+Fin de si \r
+\r
+\r
+ALERTE("Export terminé.")\r
diff --git a/import/raw_conversion/export_fonction_usage_4d.txt b/import/raw_conversion/export_fonction_usage_4d.txt
deleted file mode 100644 (file)
index de097e0..0000000
+++ /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 (file)
index 68f73cb..0000000
+++ /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 (executable)
index 0000000..cdfb1c3
--- /dev/null
@@ -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
+