File scripts/cron.php changed (mode: 100644) (index 76d38eb..db7cc6a) |
... |
... |
if (gmdate("Hi") == "0105") { |
149 |
149 |
} |
} |
150 |
150 |
|
|
151 |
151 |
if (gmdate("Hi") == "0300") { |
if (gmdate("Hi") == "0300") { |
152 |
|
rg_log("Clean old forget_pass entries..."); |
|
|
152 |
|
rg_log_enter("Clean old forget_pass entries..."); |
153 |
153 |
$sql = "DELETE FROM forgot_pass WHERE expire < $now"; |
$sql = "DELETE FROM forgot_pass WHERE expire < $now"; |
154 |
154 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
155 |
155 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
|
156 |
|
rg_log_exit(); |
156 |
157 |
} |
} |
157 |
158 |
|
|
158 |
159 |
if (gmdate("i") == "30") { |
if (gmdate("i") == "30") { |
159 |
|
rg_log("Clean old tokens..."); |
|
|
160 |
|
rg_log_enter("Clean old tokens..."); |
160 |
161 |
$sql = "DELETE FROM tokens WHERE expire < $now"; |
$sql = "DELETE FROM tokens WHERE expire < $now"; |
161 |
162 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
162 |
163 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
|
164 |
|
rg_log_exit(); |
163 |
165 |
} |
} |
164 |
166 |
|
|
165 |
167 |
if (gmdate("i") == "01") { |
if (gmdate("i") == "01") { |
166 |
|
rg_log("Clean old sess entries..."); |
|
|
168 |
|
rg_log_enter("Clean old sess entries..."); |
167 |
169 |
$sql = "DELETE FROM sess WHERE expire < $now"; |
$sql = "DELETE FROM sess WHERE expire < $now"; |
168 |
170 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
169 |
171 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
|
172 |
|
rg_log_exit(); |
170 |
173 |
} |
} |
171 |
174 |
|
|
172 |
175 |
if (gmdate("Hi") == "0605") { |
if (gmdate("Hi") == "0605") { |
173 |
|
rg_log("Clean old login_tokens_ip entries..."); |
|
|
176 |
|
rg_log_enter("Clean old login_tokens_ip entries..."); |
174 |
177 |
$sql = "DELETE FROM login_tokens_ip WHERE expire < $now"; |
$sql = "DELETE FROM login_tokens_ip WHERE expire < $now"; |
175 |
178 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
176 |
179 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
|
180 |
|
rg_log_exit(); |
|
181 |
|
} |
|
182 |
|
|
|
183 |
|
if (gmdate("dHi") == "010610") { |
|
184 |
|
rg_log_enter("Clean old empty slave tables..."); |
|
185 |
|
|
|
186 |
|
$ts = time() - 3 * 31 * 24 * 3600; |
|
187 |
|
$limit = gmdate('Y_m', $ts); |
|
188 |
|
rg_log('limit=' . $limit); |
|
189 |
|
foreach ($rg_sql_struct_slaves as $table) { |
|
190 |
|
rg_log('Slave: ' . $table); |
|
191 |
|
$sql = 'SELECT relname FROM pg_class' |
|
192 |
|
. ' WHERE relname LIKE \'' . $table . '_%\'' |
|
193 |
|
. ' AND relkind = \'r\'' |
|
194 |
|
. ' AND relname < \'' . $table . '_' . $limit . '\'' |
|
195 |
|
. ' ORDER BY relname'; |
|
196 |
|
$res = rg_sql_query($db, $sql); |
|
197 |
|
if ($res === FALSE) { |
|
198 |
|
rg_log('Cannot load slave tables: ' . rg_sql_error()); |
|
199 |
|
break; |
|
200 |
|
} |
|
201 |
|
while (($row = rg_sql_fetch_array($res))) { |
|
202 |
|
$sql = 'SELECT 1 FROM ' . $row['relname'] . ' LIMIT 1'; |
|
203 |
|
$res2 = rg_sql_query($db, $sql); |
|
204 |
|
if ($res2 === FALSE) { |
|
205 |
|
rg_log('Cannot select from table [' |
|
206 |
|
. $row['relname'] . ']: ' |
|
207 |
|
. rg_sql_error()); |
|
208 |
|
break; |
|
209 |
|
} |
|
210 |
|
$rows = rg_sql_num_rows($res2); |
|
211 |
|
rg_sql_free_result($res2); |
|
212 |
|
|
|
213 |
|
if ($rows == 1) |
|
214 |
|
continue; |
|
215 |
|
|
|
216 |
|
$sql = 'DROP TABLE ' . $row['relname']; |
|
217 |
|
$res2 = rg_sql_query($db, $sql); |
|
218 |
|
rg_sql_free_result($res2); |
|
219 |
|
} |
|
220 |
|
rg_sql_free_result($res); |
|
221 |
|
} |
|
222 |
|
|
|
223 |
|
rg_log_exit(); |
177 |
224 |
} |
} |
178 |
225 |
|
|
179 |
226 |
rg_log_cron(); |
rg_log_cron(); |