2 error_reporting(E_ALL);
3 if ((php_sapi_name() !=
'cli')) {
4 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
7 function print_usage() {
8 echo $_SERVER[
'argv'][0].
" - Import a CSV File to a csv data source";
11 echo $_SERVER[
'argv'][0].
" <SYSTEM_ROOT> <ASSETID> <CSV_PATH> <FORCE_UPDATE_TIME>\n";
13 echo
"SYSTEM_ROOT: Path to the Squiz Matrix system.\n";
14 echo
"ASSETID: Assetid of a CSV Data Source asset.\n";
15 echo
"CSV_PATH: Path to the CSV file to import\n";
16 echo
"FORCE_UPDATE_TIME: Forcibly refresh the asset's updated time, otherwise asset will not refresh updated time for setting same content.(y/n)\n";
21 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
22 if (empty($SYSTEM_ROOT)) {
23 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
28 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
29 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
34 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
36 $GLOBALS[
'SQ_SYSTEM']->setCurrentUser($GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user'));
38 $assetid = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] : 0;
39 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid,
'data_source_csv');
41 echo
"You need to supply a CSV Data Source assetid as the second argument\n";
46 if ($_SERVER[
'argc'] < 4) {
47 echo
"You need to supply the path to CSV file as the third argument\n";
51 $filepath = $_SERVER[
'argv'][3];
52 require_once SQ_FUDGE_PATH.
'/csv/csv.inc';
54 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
56 $csv =
new CSV($filepath);
59 $asset->setAttrValue(
'cached_content', $csv->values);
62 $asset->setResultSet(Array(), $asset->name);
63 $asset->getResultSet($asset->name);
65 $asset->saveAttributes();
68 $FORCE_UPDATE = (isset($_SERVER[
'argv'][4])) ? $_SERVER[
'argv'][4] :
'n';
69 if(strtolower($FORCE_UPDATE) ==
'y') {
73 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();