Import custom fields

More
14 years 3 months ago #9097 by theDigger
Hi,

I'd like to share a tip of a way to import data from an other application. In my case this was from docman in an old joomla 1.0 installation.

I made a Ruby script that connects to the old database and then posts the data to the frontend content submission form.
Code:
require "rubygems" require "active_record" require 'rest_client' require 'iconv' require 'htmlentities' Skold = { :adapter => "mysql", :host => "localhost", :port => 8888, :database => "skold", :username => "root", :password => "", :socket => "/Applications/MAMP/tmp/mysql/mysql.sock", :encoding => "latin1" } #Skold - Old database class Docman < ActiveRecord::Base establish_connection Skold set_table_name 'jos_docman' set_primary_key 'id' belongs_to :category, :foreign_key => 'catid' end class Category < ActiveRecord::Base establish_connection Skold set_table_name 'jos_categories' set_primary_key 'id' has_many :docmans, :foreign_key => 'catid' end path = '/Users/nils/Sites/skold/dmdocuments/' charset = Iconv.new('UTF-8','LATIN1') html = HTMLEntities.new Docman.all.each do |l| response = RestClient.post( 'http://localhost:8888/smartklubben/index.php?option=com_flexicontent&view=items&layout=form&typeid=2&Itemid=3', :task => 'save', :vstate => 2, :state => 1, :created_by => 62, :created => l.dmdate_published, :id => 0, :title => charset.iconv(l.dmname), :text => html.decode(charset.iconv(l.dmdescription)), #Decode html entities and convert LATIN1 to UTF-8 :'oldcat[]' => l.category.title, :arskurs_from => -1, :arskurs_tom => 13, :'cid[]' => 2, :lesson => File.exist?(path + l.dmfilename)? File.new(path + l.dmfilename, 'rb'):'' ) puts "Import ok" if response.code == 200 puts "File #{l.dmfilename} skipped for #{l.id}" if !File.exist?(path + l.dmfilename) end

oldcat[] and arskurs_from is examples of custom fields.

In order to make it easy I installed this plugin: extensions.joomla.org/extensions ... tion/10391 to automatically have a admin user session active. I also added these lines to the plugin at line 47 to circumvent the token check.
Code:
$token = JUtility::getToken(); $_POST[$token] = 1;

Remember to uninstall the "Hack me" plugin when you are done!

I used Ruby because it was the easiest way for me to do it but you can rewrite the script in php if you want.

/Nils

Please Log in or Create an account to join the conversation.

More
14 years 3 months ago #9223 by micker
Replied by micker on topic Import custom fields
thanks !

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.387 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline