Dec 04, 2008, 12:40 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Donate to MODx: Donations
Pages: [1]   Go Down
  Print  
Author Topic: [Solved] Export TV's content into custom DB table : Ditto + CSV = simple + easy  (Read 760 times)
0 Members and 1 Guest are viewing this topic.
davidm
Marketing & Design Team
*
Posts: 6,777


The best way to predict the future is to invent it


WWW
« on: Mar 28, 2008, 11:23 AM »

I am working on a project which requires me to export the data contained in several TVs into a single table with several fields. This might also become a bounty (if I manage to sell this to the client) to develop a module to automate such an export (not immediate need but I try to look forward...). I'll also probably need to work on importing custom DB tables into TVs but let's talk about this later Tongue

This will take some work from me as I am not a MySQL wizard (though I have started toying more and more with MySQL, importing data from other systems and custom tables into modx_site_content with success), and before I start I'd like either some feedback from people who did it and possibly advice about the process.

I am surprised this has never has been raised (or at last, I didn't find the threads !)

The first thing I plan to do is graphically "map" the fields I need in the custom DB table to the MODx fields which contains the data. Of course, given the way TVs are stored, it will mean mapping fields from several tables (modx_site_content, modx_site_tmplvar_contentvalues for content, and ) with fields from a single table with each field representing a TV.

From modx_site_tmplvar_contentvalues, I need those fields :

tmplvarid -> that's the value I need to tie TVs to the fields I'll create in the custom table
contentid -> that's the value I need to tie modx_site_tmplvar_contentvalues to modx_site_content
value -> that's the content I'll need to move from TVs to the fields I'll create in the custom table

From modx_site_content, I need those fields :

id -> that's the value I need to tie modx_site_content to modx_site_tmplvar_contentvalues
pagetitle -> that's the content I'll need to import into the title field of my custom table
parent  -> that's the field I'll need to sort which documents I need to "extract" from the MODx DB
content -> not used in my case, all the data I need is stored in TVs.
« Last Edit: Mar 28, 2008, 02:34 PM by davidm » Logged

.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez à l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.45 - PHP 5.2.6 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net
Bruno17
Full Member
***
Posts: 141


« Reply #1 on: Mar 28, 2008, 12:22 PM »

Perhaps you can use something from this one for reading the TVs (xdbfilter):

http://modxcms.com/forums/index.php/topic,23570.0.html

here a little demo : http://www.meine-goldschmiede.de/index.php?id=34

@INHERIT is not implemented but Im working on it
« Last Edit: Mar 28, 2008, 12:25 PM by Bruno17 » Logged

davidm
Marketing & Design Team
*
Posts: 6,777


The best way to predict the future is to invent it


WWW
« Reply #2 on: Mar 28, 2008, 12:37 PM »

Thanks Bruno but I fail to see how it relates to what I am trying to achieve ?

If you need more information, I need to export TVs into a custom DB table for my client to exploit it outside the context of the web.
Logged

.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez à l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.45 - PHP 5.2.6 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net
ganeshXL
Testers
*
Posts: 1,549



WWW
« Reply #3 on: Mar 28, 2008, 12:42 PM »

Code:

SELECT
sc.id,
sc.pagetitle,
tv.value

FROM
modx_site_content AS sc,
modx_site_tmplvar_contentvalues AS tv

WHERE sc.parent=55
AND sc.id=tv.contentid
AND tv.tmplvarid=10

GROUP BY sc.id

ORDER BY sc.id ASC


This is an example of exporting one particular TV type (gigLocation = identifier 10), where the document parent is 55, along with the doc id + pagetitle.

It won't automagically insert that data into your custom DB table, and things get a bit more complicated when you want to export several TVs in one go.

Personally, I'd extract the values with PHP, build an multidimensional array, and finally do one INSERT or UPDATE statement for your custom DB table.
I would probably keep the unique ids from the modx-document, to make bughunting etc. easier. Or create one field "original_modx_id" for reference.

You could even use Ditto to spit out a tab-delimited list of all values with your custom tpls, and then use this for import via phpMyAdmin.
Logged

davidm
Marketing & Design Team
*
Posts: 6,777


The best way to predict the future is to invent it


WWW
« Reply #4 on: Mar 28, 2008, 12:46 PM »

Thanks a lot that's exactly what I am looking for !
Great insight and advices Smiley

Never occured to me to have Ditto spit out a csv list, awesome idea !
You might just have made this a LOT easier for me, off to experiment !!!

Sure, using PHP would make things way easier and make automating this process possible but I am still short on PHP to achieve that Sad
I might give it a try anyway, might be a way to learn along the way...
« Last Edit: Mar 28, 2008, 12:52 PM by davidm » Logged

.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez à l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.45 - PHP 5.2.6 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net
Bruno17
Full Member
***
Posts: 141


« Reply #5 on: Mar 28, 2008, 12:49 PM »

This snippet has functions which read all fields from an document and the tvs in an array. I think you can modify this to write the array in a new or existing db.
Logged

davidm
Marketing & Design Team
*
Posts: 6,777


The best way to predict the future is to invent it


WWW
« Reply #6 on: Mar 28, 2008, 01:06 PM »

Ok sorry I didn't understand this, where can I download this snippet ?

Found it : http://modxcms.com/forums/index.php/topic,23570.msg145591.html#msg145591

I'll look at this right now !
Logged

.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez à l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.45 - PHP 5.2.6 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net
davidm
Marketing & Design Team
*
Posts: 6,777


The best way to predict the future is to invent it


WWW
« Reply #7 on: Mar 28, 2008, 02:27 PM »

You could even use Ditto to spit out a tab-delimited list of all values with your custom tpls, and then use this for import via phpMyAdmin.

Sometimes the simplest ideas are just the brightest !
I just managed to import my TV's data into the custom DB table Grin

All in 30 minutes... woooot, I love Ditto !

I'll document the process, as it opens many doors to exporting data for clients...

If you come to Paris, I'll buy you diner and a nice wine !

Logged

.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez à l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.45 - PHP 5.2.6 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net
ganeshXL
Testers
*
Posts: 1,549



WWW
« Reply #8 on: Mar 28, 2008, 02:38 PM »

Quote
If you come to Paris, I'll buy you diner and a nice wine !

entendu!  Smiley
Logged

Bruno17
Full Member
***
Posts: 141


« Reply #9 on: Mar 29, 2008, 02:24 AM »

Hey, thats realy a cool idea!
And if you want only a part of the rows you can use xdbfilter to select the needed ones.
Logged

davidm
Marketing & Design Team
*
Posts: 6,777


The best way to predict the future is to invent it


WWW
« Reply #10 on: Mar 29, 2008, 07:07 AM »

I really need to take more time to get into xdbfilter, remember I am no dev... but there is big potential for that snippet !

Anyway, yesterday I did a small succesful test but today I exported / imported into my custom DB all the records (125 of them, 20 fields) with no errors Grin  It took some tweaking of the CSV parameters but it works fine : really powerful !

I'll write up a tutorial to post in Tips and Tricks and the Wiki later next week...
Logged

.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez à l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.45 - PHP 5.2.6 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!