1

Recently I have started developing an extension for Joomla3 and I have a serious feeling that I'm missing something basic about the import feature. I do know that it's possible to import some dummy data by using .sql files, but this works mainly for the custom created tables specific only for this extension. But what if I want to insert some data in Joomla core tables like #__content, #__menu, $__modules ? That's still possible with using .sql files, but then I must be cautious not to overwrite something, not to create doubled entries, create relations with other tables and so on. That's quite complex process and prone to errors, in WordPress this feature is extremly simple and I think that Joomla also has such option, but I couldn't find it. I will be gratefull for any tips and tricks :)

ArturoO
  • 611
  • 7
  • 19
  • On a clean Joomla install, there is an option for installing sample data. Are you trying to install sample data into an already developed site? – versalle88 Dec 08 '14 at 18:53
  • Developed extension will be installed on various websites, so in most cases there will be already an existing content. I need to create additional content for my extension, where users can check how it works properly. – ArturoO Dec 08 '14 at 19:18
  • As long as you do INSERT statements, you should be fine. Don't set the ID and Joomla will auto-increment when it runs the insert. I would suggest writing an install script, though, that allows the user to install sample data or skip it if they prefer not to have it. – versalle88 Dec 08 '14 at 19:29
  • Right now I'm using the mentioned INSERT method(with additional IGNORE instruction), but to my surprise the 'alias' column in #__content table isn't set as UNIQUE. Because of that, I might add redundant articles with the same alias and there won't be any error. This will of course cause problems later, when the user tries to edit the created article. Because of such problems I thought that there's an easier way of doing this on Joomla. – ArturoO Dec 08 '14 at 19:47
  • 1
    No no no do not use sql for this purpose, use the correct APIs for each table, otherwise you will have problems with nested sets and with assets. Do this in a postflight script. – Elin Dec 09 '14 at 06:05
  • @Elin hi there, my problem differs but kind of same i was searching for a way to import dummy data into socialize jomsocial template, can you help me in this ? Thanks – Habib Rehman Jul 26 '16 at 06:49

1 Answers1

0

Ok, it seems that I have found the solution thanks to the comment from Elin. It's necessary to use JTable class in PHP code to add articles programmatically, source: https://zunostudios.com/blog/development/204-using-the-joomla-api-to-add-articles-programmatically

ArturoO
  • 611
  • 7
  • 19