28 error_reporting(E_ALL);
29 if (ini_get(
'memory_limit') !=
'-1') ini_set(
'memory_limit',
'-1');
31 if ((php_sapi_name() !=
'cli')) trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
33 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
34 if (empty($SYSTEM_ROOT)) {
35 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
39 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
40 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
44 $import_file = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] :
'';
45 if (empty($import_file) || !is_file($import_file)) {
46 echo
"You need to supply the path to the import file as the second argument\n";
50 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
53 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
55 $pages = file($import_file);
56 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
57 $csv_fd = fopen($import_file,
'r');
59 while (($data = fgetcsv($csv_fd, 1024,
',')) !== FALSE) {
61 if (count($data) != 4) {
62 echo
"Wrong number of arguments passed on line #$line_number : ".implode(
', ', $data).
"\n";
67 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(trim($data[1]));
69 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset(trim($data[2]),
'', TRUE);
70 if (is_null($parent_asset)) {
71 echo
"New parent asset #{$data[2]} does not exist on line #$line_number\n";
76 $import_link = Array(
'asset' => &$parent_asset,
'link_type' => $data[3]);
78 $new_asset_type = trim($data[1]);
80 $new_page =
new $new_asset_type();
81 $new_page->setAttrValue(
'name', trim($data[0]));
83 if (!$new_page->create($import_link)) {
84 echo
'Failed to import '.$new_asset_type.
' '.trim($data[0]);
88 bam(
'New '.$new_page->type().
' asset created for '.trim($data[0]).
' - asset ID #'.$new_page->id);
93 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();