| | 260 | |
|---|
| | 261 | // Append sitegroup name |
|---|
| | 262 | $sitegroup_base = "{$global_base}/" . $this->safe_sg_name($subscription->sitegroup); |
|---|
| | 263 | if (!is_dir($sitegroup_base)) |
|---|
| | 264 | { |
|---|
| | 265 | // The configuration key might have dynamic part to it |
|---|
| | 266 | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| | 267 | debug_add("directory {$sitegroup_base} does not exist, creating", MIDCOM_LOG_DEBUG); |
|---|
| | 268 | if (!mkdir($sitegroup_base)) |
|---|
| | 269 | { |
|---|
| | 270 | // TODO: Error reporting |
|---|
| | 271 | debug_add("could not create directory {$sitegroup_base}", MIDCOM_LOG_ERROR); |
|---|
| | 272 | debug_pop(); |
|---|
| | 273 | return false; |
|---|
| | 274 | } |
|---|
| | 275 | debug_pop(); |
|---|
| | 276 | } |
|---|
| | 277 | |
|---|
| | 278 | $subscription_path = "{$sitegroup_base}/{$subscription->guid}"; |
|---|
| | 279 | if (!is_dir($subscription_path)) |
|---|
| | 280 | { |
|---|
| | 281 | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| | 282 | debug_add("directory {$subscription_path} does not exist, creating", MIDCOM_LOG_DEBUG); |
|---|
| | 283 | if (!mkdir($subscription_path)) |
|---|
| | 284 | { |
|---|
| | 285 | // TODO: Error reporting |
|---|
| | 286 | debug_add("could not create directory {$subscription_path}", MIDCOM_LOG_ERROR); |
|---|
| | 287 | debug_pop(); |
|---|
| | 288 | return false; |
|---|
| | 289 | } |
|---|
| | 290 | debug_pop(); |
|---|
| | 291 | } |
|---|
| | 292 | return $subscription_path; |
|---|
| | 293 | } |
|---|
| | 294 | |
|---|
| | 295 | function _get_subscription_quarantine_basedir(&$subscription) |
|---|
| | 296 | { |
|---|
| | 297 | $global_base = $this->_config->get('queue_root_dir'); |
|---|
| | 298 | if (!is_dir($global_base)) |
|---|
| | 299 | { |
|---|
| | 300 | // The configuration key might have dynamic part to it |
|---|
| | 301 | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| | 302 | debug_add("directory {$global_base} does not exist, creating", MIDCOM_LOG_DEBUG); |
|---|
| | 303 | if (!mkdir($global_base)) |
|---|
| | 304 | { |
|---|
| | 305 | // TODO: Error reporting |
|---|
| | 306 | debug_add("could not create directory {$global_base}", MIDCOM_LOG_ERROR); |
|---|
| | 307 | debug_pop(); |
|---|
| | 308 | return false; |
|---|
| | 309 | } |
|---|
| | 310 | debug_pop(); |
|---|
| | 311 | } |
|---|
| 290 | | function _get_subscription_quarantine_basedir(&$subscription) |
|---|
| 291 | | { |
|---|
| 292 | | $global_base = $this->_config->get('queue_root_dir'); |
|---|
| 293 | | if (!is_dir($global_base)) |
|---|
| 294 | | { |
|---|
| 295 | | // The configuration key might have dynamic part to it |
|---|
| 296 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 297 | | debug_add("directory {$global_base} does not exist, creating", MIDCOM_LOG_DEBUG); |
|---|
| 298 | | if (!mkdir($global_base)) |
|---|
| 299 | | { |
|---|
| 300 | | // TODO: Error reporting |
|---|
| 301 | | debug_add("could not create directory {$global_base}", MIDCOM_LOG_ERROR); |
|---|
| 302 | | debug_pop(); |
|---|
| 303 | | return false; |
|---|
| 304 | | } |
|---|
| 305 | | debug_pop(); |
|---|
| 306 | | } |
|---|
| 307 | | |
|---|
| 308 | | // Append sitegroup name |
|---|
| 309 | | $sitegroup_base = "{$global_base}/" . $this->safe_sg_name($subscription->sitegroup); |
|---|
| 310 | | if (!is_dir($sitegroup_base)) |
|---|
| 311 | | { |
|---|
| 312 | | // The configuration key might have dynamic part to it |
|---|
| 313 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 314 | | debug_add("directory {$sitegroup_base} does not exist, creating", MIDCOM_LOG_DEBUG); |
|---|
| 315 | | if (!mkdir($sitegroup_base)) |
|---|
| 316 | | { |
|---|
| 317 | | // TODO: Error reporting |
|---|
| 318 | | debug_add("could not create directory {$sitegroup_base}", MIDCOM_LOG_ERROR); |
|---|
| 319 | | debug_pop(); |
|---|
| 320 | | return false; |
|---|
| 321 | | } |
|---|
| 322 | | debug_pop(); |
|---|
| 323 | | } |
|---|
| 324 | | $subscription_path = "{$sitegroup_base}/{$subscription->guid}-quarantine"; |
|---|
| 325 | | if (!is_dir($subscription_path)) |
|---|
| 326 | | { |
|---|
| 327 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 328 | | debug_add("directory {$subscription_path} does not exist, creating", MIDCOM_LOG_DEBUG); |
|---|
| 329 | | if (!mkdir($subscription_path)) |
|---|
| 330 | | { |
|---|
| 331 | | // TODO: Error reporting |
|---|
| 332 | | debug_add("could not create directory {$subscription_path}", MIDCOM_LOG_ERROR); |
|---|
| 333 | | debug_pop(); |
|---|
| 334 | | return false; |
|---|
| 335 | | } |
|---|
| 336 | | debug_pop(); |
|---|
| 337 | | } |
|---|
| 338 | | return $subscription_path; |
|---|
| 339 | | } |
|---|
| 340 | | |
|---|
| 418 | | * Helper for process_queue, quarantines failed items |
|---|
| | 423 | * Helper for process_queue, moves quarantined items to correct directory |
|---|
| | 424 | */ |
|---|
| | 425 | function _quarantine_items(&$q_items, &$items_paths, &$subscription) |
|---|
| | 426 | { |
|---|
| | 427 | if (!is_array($q_items)) |
|---|
| | 428 | { |
|---|
| | 429 | return false; |
|---|
| | 430 | } |
|---|
| | 431 | if (empty($q_items)) |
|---|
| | 432 | { |
|---|
| | 433 | return true; |
|---|
| | 434 | } |
|---|
| | 435 | $quarantine_path = $this->_get_subscription_quarantine_queuedir($subscription); |
|---|
| | 436 | if (!is_dir($quarantine_path)) |
|---|
| | 437 | { |
|---|
| | 438 | // Could not get valid dir |
|---|
| | 439 | return false; |
|---|
| | 440 | } |
|---|
| | 441 | foreach ($q_items as $item_key => $item_path) |
|---|
| | 442 | { |
|---|
| | 443 | // Reset time limit counter while processing files |
|---|
| | 444 | set_time_limit(30); |
|---|
| | 445 | $quarantine_filepath = $quarantine_path . '/' . basename($item_path); |
|---|
| | 446 | debug_add("Quarantineing '{$item_key}' as '{$quarantine_filepath}'", MIDCOM_LOG_DEBUG); |
|---|
| | 447 | $output = array(); |
|---|
| | 448 | $code = 0; |
|---|
| | 449 | exec("mv {$item_path} {$quarantine_filepath}", $output, $code); |
|---|
| | 450 | if ($code != 0) |
|---|
| | 451 | { |
|---|
| | 452 | debug_add("Failed to quarantine '{$item_path}' as '{$quarantine_filepath}'", MIDCOM_LOG_ERROR); |
|---|
| | 453 | continue; |
|---|
| | 454 | } |
|---|
| | 455 | |
|---|
| | 456 | // TODO: write per-item error if available to some index file. |
|---|
| | 457 | |
|---|
| | 458 | unset($q_items[$item_key], $items_paths[$item_key]); |
|---|
| | 459 | } |
|---|
| | 460 | return true; |
|---|
| | 461 | } |
|---|
| | 462 | |
|---|
| | 463 | |
|---|
| | 464 | /** |
|---|
| | 465 | * Helper for process_queue, removes processed items, quarantines failed ones |
|---|
| 428 | | debug_add("Transporter left key '{$item_key}' into items, quarantineing '{$item_path}'", MIDCOM_LOG_INFO); |
|---|
| 429 | | $quarantine_path = $this->_get_subscription_quarantine_queuedir($subscription); |
|---|
| 430 | | if (!is_dir($quarantine_path)) |
|---|
| 431 | | { |
|---|
| 432 | | // Could not get valid dir |
|---|
| 433 | | continue; |
|---|
| 434 | | } |
|---|
| 435 | | $quarantine_filepath = $quarantine_path . '/' . basename($item_path); |
|---|
| 436 | | $output = array(); |
|---|
| 437 | | $code = 0; |
|---|
| 438 | | exec("mv {$item_path} {$quarantine_filepath}", $output, $code); |
|---|
| 439 | | if ($code != 0) |
|---|
| 440 | | { |
|---|
| 441 | | debug_add("Failed to quarantine '{$item_path}' as '{$quarantine_filepath}'", MIDCOM_LOG_ERROR); |
|---|
| 442 | | } |
|---|
| 443 | | else |
|---|
| 444 | | { |
|---|
| 445 | | debug_add("Quarantined '{$item_path}' as '{$quarantine_filepath}'", MIDCOM_LOG_INFO); |
|---|
| 446 | | } |
|---|
| 447 | | // TODO: create notice |
|---|
| | 476 | debug_add("Transporter left key '{$item_key}' into items, marking for quarantineing", MIDCOM_LOG_INFO); |
|---|
| | 477 | $q_items[$item_key] = $item_path; |
|---|