APC Action Applications - Home Page

Frequently Asked Questions v2


The script /misc/file2slice/importer.php3 contains a function importer, which can import a CSV (comma-separated-values) file into your slice.

The data file should contain field names (any names, not from AA) on the first line, separated by your chosen separator. The next lines contain the items, one item per line, fields separated by the same separator.

Johny Bravo, he is a real good guy, johny@bravo.uk, fr, VIP+fools
France Newman, a noname boy, france.newman@noname.org, en, nonames+fools

Here, the separator is comma, but it may be any other string.

The function trimmes each field from whitespace. It has these parametres:

You don't have to set all the parametres - the last one required is postedBy, the next ones have default values.

The "fire" parameter works as a safe mode. You can prepare your data with "fire" set to false and when you are sure that what you see on the screen is what you want to be added to the database (by the StoreItem function), you may set "fire" to true.


The array "actions" should look like this:

$actions = array(
"created_by......" => array("action" => "store", "from" => "AUTHOR"),
"category.......1" => array("action" => "storeparsemulti", "delimiter" => "+", "from" => "CATEGORY"),
"language.......1" => array("action" => "storetrans", "from" => "LANGUAGE", "flag" => 1, "trans"=>array("en"=>"english","fr"=>"french"))

It contains the AA field names followed by how to get their content. You may set flags (e.g. "flag" => 1 means HTML content) with any action.

The actions are as follows:

A fully functional example script

$actions = array(
"category.......1" => array("action" => "storeparsemulti", "delimiter" => ";", "from" => "Category"),
"headline........" => array("action" => "store", "from" => "Title"),
"created_by......" => array("action" => "store", "from" => "Author"),
"full_text......." => array("action" => "store", "from" => "Summary", "flag"=>1)

require "./importer.php3";

Importer ( "aa65a21b285c25f9fe0d4b662919b4b2", // slice iD
	"./books.txt",                      // file name
	"t",                               // field separator
	"uid=ada01,ou=People,ou=AA",        // posted by (there should be a number for sql permissions)
	true,                               // write to DB?
	600);                               // time limit in seconds


Related Articles:

How to import big exported slice&data?

Last Edit: Aug 17 2011

<aafaq id=1731> ~ToDo: 1731 How to import lots of data into a slice? </aafaq> 

This FAQ interface was developed by Jason at Commons.ca

APC: Internet and ICTs for social justice and development APC ActionApps is a free software content management system initiated by the Association for Progressive Communications (APC)
APC - Internet and ICTs for social justice and development