/
pslist
executable file
·100 lines (97 loc) · 3.44 KB
/
pslist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env php
<?php
require(__DIR__ . "/inc/common.php");
define("PSCMD","list");
try {
psCli::init($argv);
$args = psCli::$args;
$objects = array_shift($args);
psCli::readcfg(Array("global","list",$objects));
$args=psCli::$args;
array_shift($args);
if (strlen($objects)==0) {
PsOut::error("Error! Enter objects you want to list.\n" . basename(__FILE__)
. " [--or] resource [filter]... [id]... [property]\n"
. "Filter(s):\n"
. "property=value to match exactly\n"
. "property>value to match objects with property bigger than value\n"
. "property<value to match objects with property lower than value\n"
. "property%>value to match objects with property newer than value (DateTime format)\n"
. "property%<value to match objects with property older than value (DateTime format)\n"
. "property~value to match objects with property matched by regexp\n"
. "property!~value to match objects with property not matched by regexp\n"
. "property!=value to match object not equal to value\n"
. "number to match only objects with this ids\n"
. "property to output given property.\n"
. "Use --help to get more informations\n\n"
);
}
$object = psCli::subobject($objects);
$properties = psCli::$properties;
$ids=Array();
$filter=Array();
foreach ($args as $arg) {
if (is_numeric($arg)) {
$ids[$arg]=$arg;
} else {
$filter[] = $arg;
}
}
if (sizeof($filter)>0) {
psFilter::create($filter,$objects);
}
if (psCli::$debug) {
psOut::msg("Filter: ".print_r($filter,true)."\n");
if (sizeof($ids)>0) {
psOut::msg("IDs to filter: ".print_r($ids,true)."\n");
}
}
psCli::initApi();
$opt = array('resource' => $objects);
if (psCli::$apifields) {
$opt['display']="[".join(",",array_keys(psCli::$apifields))."]";
}
if (sizeof(psCli::$apifilter)>0) {
foreach (psCli::$apifilter as $f =>$v) {
if ($v!=psFilter::F_NA) {
$opt["filter[$f]"]="[$v]";
}
}
}
psOut::progress("Getting data for $objects($object)...");
$xml=psCli::apiCmd("get",$opt);
psOut::progress(sprintf("Got %d objects. ",count($xml->$objects->children())));
$data = $xml->$objects->children();
$row = 0;
$rows = Array();
$cnt = sizeof($data);
psOut::begin($objects, $object);
foreach ($data as $r) {
$id = (string) $r->id;
if (sizeof($ids)>0 && !array_key_exists($id,$ids)) {
continue;
}
$rowdata = psGet::getValues($r);
if (psFilter::$enabled) {
psOut::progress(false, $row, $cnt);
if (psFilter::$enabled && psFilter::isFiltered($r)) {
if (psCli::$debug)
psOut::msg("Filtering $object $id due to filter.\n");
continue;
}
$rowdata2=Array();
foreach (psCli::$properties as $p=>$v) {
$rowdata2[$p]=$rowdata[$p];
}
psOut::write($rowdata2);
} else {
psOut::write($rowdata);
}
$row++;
}
psOut::end($objects, $object);
} catch (PrestaShopWebserviceException $e) {
// Here we are dealing with errors
$trace = $e->getTrace();
PsOut::error('Other error<br />' . $e->getMessage());
}