Subversion Repositories oidplus

Rev

Rev 1116 | Rev 1162 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1116 Rev 1130
Line 39... Line 39...
39
	if ($oid == '') continue;
39
	if ($oid == '') continue;
40
 
40
 
41
	check_oid($oid);
41
	check_oid($oid);
42
}
42
}
43
 
43
 
-
 
44
/**
-
 
45
 * @param string $oid
-
 
46
 * @return void
-
 
47
 */
44
function check_oid($oid) {
48
function check_oid(string $oid) {
45
 
49
 
46
	$res = OIDplus::db()->query("select * from ###objects where id = ?", array("oid:$oid"));
50
	$res = OIDplus::db()->query("select * from ###objects where id = ?", array("oid:$oid"));
47
	$ok = $res->num_rows() > 0;
51
	$ok = $res->num_rows() > 0;
48
 
52
 
49
	if (!$ok) {
53
	if (!$ok) {
Line 54... Line 58...
54
 
58
 
55
echo "OK\n";
59
echo "OK\n";
56
 
60
 
57
# ---
61
# ---
58
 
62
 
-
 
63
/**
-
 
64
 * @param string $oid
-
 
65
 * @param string $root
-
 
66
 * @return void
-
 
67
 */
59
function add_oid($oid, $root=DESIRED_ROOT) {
68
function add_oid(string $oid, string $root=DESIRED_ROOT) {
60
	if (VERBOSE) echo "Adding $oid ...\n";
69
	if (VERBOSE) echo "Adding $oid ...\n";
61
	$data = ft_get_oid_data($oid);
70
	$data = ft_get_oid_data($oid);
62
 
71
 
63
	if (!isset($data['oid'])) {
72
	if (!isset($data['oid'])) {
64
		echo "Warning: Cannot gain information about OID $oid\n";
73
		echo "Warning: Cannot gain information about OID $oid\n";
Line 106... Line 115...
106
 
115
 
107
	sql_execute("insert into ###objects (id, parent, title, description, ra_email, created, updated) values (?, ?, ?, ?, ?, ?, ?)",
116
	sql_execute("insert into ###objects (id, parent, title, description, ra_email, created, updated) values (?, ?, ?, ?, ?, ?, ?)",
108
		array("oid:$oid", "oid:$parent", $title, $description, $ra_email, $created, $updated));
117
		array("oid:$oid", "oid:$parent", $title, $description, $ra_email, $created, $updated));
109
}
118
}
110
 
119
 
-
 
120
/**
-
 
121
 * @param string $oid
-
 
122
 * @return false|array
-
 
123
 */
111
function ft_get_oid_data($oid) {
124
function ft_get_oid_data(string $oid) {
112
	$url = OIDplus::baseConfig()->getValue('OIDINFO_API_URL') . '&oid='.urlencode($oid);
125
	$url = OIDplus::baseConfig()->getValue('OIDINFO_API_URL') . '&oid='.urlencode($oid);
113
	$cont_json = @file_get_contents($url);
126
	$cont_json = @file_get_contents($url);
114
	if (!$cont_json) {
127
	if (!$cont_json) {
115
		sleep(5);
128
		sleep(5);
116
                $cont_json = @file_get_contents($url);
129
                $cont_json = @file_get_contents($url);
117
                if (!$cont_json) return false;
130
                if (!$cont_json) return false;
118
	}
131
	}
119
	$data = json_decode($cont_json,true);
132
	return json_decode($cont_json,true);
120
 
-
 
121
	return $data;
-
 
122
}
133
}
123
 
134
 
-
 
135
/**
-
 
136
 * @param string $sql
-
 
137
 * @param array|null $prep
-
 
138
 * @return void
-
 
139
 */
124
function sql_execute($sql, $prep=null) {
140
function sql_execute(string $sql, array $prep=null) {
125
#	echo "$sql\n";
141
#	echo "$sql\n";
126
	try {
142
	try {
127
		OIDplus::db()->query($sql, $prep);
143
		OIDplus::db()->query($sql, $prep);
128
	} catch (Exception $e) {
144
	} catch (Exception $e) {
129
		echo "Warning: " . $e->getMessage() . "\n";
145
		echo "Warning: " . $e->getMessage() . "\n";