Commit 8734afdc authored by Stephane Crozat's avatar Stephane Crozat

Documentation et amélioration de l'export XSLT->BD->CSV

parent b40a2573
Passer TODO sur GitLab
Intégrer branch Remy
Améliorer PHP (dates, ajouter texte info)
Backup DB
HTTPS
Gestion d'erreurs DB
......
......@@ -10,6 +10,7 @@ CREATE TABLE api (
dend DATE NOT NULL,
size INTEGER,
ects INTEGER NOT NULL,
mail TEXT NOT NULL,
CHECK (code>0),
CHECK (year>2018 AND year<2100),
CHECK (semester IN ('H','E')),
......@@ -28,10 +29,10 @@ CREATE TABLE subscribe (
/** Test dataset
INSERT INTO api VALUES (
1,'Poésie et ingénierie',2019,'H',TO_DATE('20190121','yyyymmdd'),TO_DATE('20190125','yyyymmdd'),24,2
1,'Poésie et ingénierie',2019,'H',TO_DATE('20190121','yyyymmdd'),TO_DATE('20190125','yyyymmdd'),24,2,'stc@utc.fr'
);
INSERT INTO api VALUES (
2,'Cloud big data blockchain IA',2019,'H',TO_DATE('20190125','yyyymmdd'),TO_DATE('20190131','yyyymmdd'),12,3
2,'Cloud big data blockchain IA',2019,'H',TO_DATE('20190125','yyyymmdd'),TO_DATE('20190131','yyyymmdd'),12,3,'stc@utc.fr'
);
INSERT INTO subscribe VALUES (
'crozatst',1,TO_DATE('20181018','YYYYMMDD')
......@@ -41,10 +42,10 @@ INSERT INTO subscribe VALUES (
CREATE OR REPLACE VIEW vApi AS
SELECT
ap.code,
CASE WHEN ap.code<10 THEN '000'||ap.code WHEN ap.code>=10 THEN '00'||ap.code END AS normcode,
CASE WHEN ap.code<10 THEN '000'||ap.code WHEN ap.code>=10 THEN '00'||ap.code END AS normcode,
ap.name, ap.year, ap.semester,
TO_CHAR(ap.dbegin,'TMday FMDD TMmonth') AS dbegin, TO_CHAR(ap.dend,'TMday FMDD TMmonth') AS dend,
size, ects
ap.size, ap.ects, ap.mail
FROM api ap
ORDER BY ap.year, ap.semester, ap.dbegin, ap.dend, ap.code;
......
ADD catalogue.website
<?xml-stylesheet href="export_sql.xsl" type="text/xsl"?>
# Génération du fichier SQL à partir de l'archive XML de Scenari
Dans Scenari, depuis `catalogue.website`, exporter une archive (clic droit)
mv catalogue*.scar catalogue.zip
rm -rf catxml
unzip catalogue.zip -d catxml
Ouvrir le fichier `catalogue.website` avec Oxygen ajouter le ligne
`<?xml-stylesheet href="/media/stc/data/git/apisub/tmp/export/export_sql.xsl" type="text/xsl"?>` juste avant la balise racine sc:item
Générer et récupérer le SQL
# Génération CSV depuis la base Postgres
\COPY (SELECT * FROM vApi) TO 'api.csv' CSV HEADER DELIMITER ';' QUOTE '"'
\COPY (SELECT DISTINCT mail FROM vApi) TO 'api_ml.txt'
scp stc@pic.crzt.fr:/home/stc/api*.* .
# MAJ site sur le serveur web
Générer et télécharger depuis Scenari
rm -rf apihtml
unzip api_gen_simpleSite.zip -d apihtml
rsync -va apihtml/* wapint@stargate.utc.fr:/volgen/user1x/users/wapint/public_html/
# MAJ catalogue sur le serveur web
rm -rf cathtml
unzip catalogue_gen_site.zip -d cathtml
rsync -va cathtml/* wapint@stargate.utc.fr:/volgen/user1x/users/wapint/public_html/cat/
\COPY (SELECT * FROM vApi) TO 'api.csv' CSV HEADER DELIMITER ';'
......@@ -11,9 +11,11 @@
<xsl:output method="text"></xsl:output>
<xsl:template match="/sc:item">
<xsl:text>INSERT INTO api (code,name,year,semester,dbegin,dend,size,ects) VALUES</xsl:text>
<xsl:text>BEGIN;</xsl:text>
<xsl:text>INSERT INTO api (code,name,year,semester,dbegin,dend,size,ects,mail) VALUES</xsl:text>
<xsl:apply-templates select="of:webSite/sp:home/of:page/sp:subPage"/>
;
<xsl:text>COMMIT;</xsl:text>
</xsl:template>
<xsl:template match="sp:subPage">
......@@ -43,6 +45,9 @@
<xsl:variable name="ects">
<xsl:value-of select="number(.//sp:info[of:block/of:blockM/sp:title='ECTS']//sc:para)"/>
</xsl:variable>
<xsl:variable name="mail">
<xsl:value-of select=".//sp:info[of:block/of:blockM/sp:title='Mail']//sc:para"/>
</xsl:variable>
(
<xsl:value-of select="$code"/>,
'<xsl:value-of select="substring($title,8)"></xsl:value-of>',
......@@ -51,7 +56,11 @@
TO_DATE('<xsl:value-of select="$begin"/>/19','DD/MM/YY'),
TO_DATE('<xsl:value-of select="$end"/>/19','DD/MM/YY'),
<xsl:value-of select="$size"/>,
<xsl:value-of select="$ects"/>
<xsl:value-of select="$ects"/>,
<xsl:choose>
<xsl:when test="$mail=''">NULL</xsl:when>
<xsl:otherwise>'<xsl:value-of select="$mail"/>'</xsl:otherwise>
</xsl:choose>
)
</xsl:template>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment