tao.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. class zahostTao extends zahostModel
  3. {
  4. /**
  5. * 将没有插入到 image 表的镜像数据插入到 image 表中。
  6. * Insert image list.
  7. *
  8. * @param array $imageList
  9. * @param int $hostID
  10. * @param array $downloadedImageList
  11. * @access protected
  12. * @return bool
  13. */
  14. protected function insertImageList($imageList, $hostID, $downloadedImageList)
  15. {
  16. $refreshPageData = false;
  17. foreach($imageList as $remoteImage)
  18. {
  19. $downloadedImage = zget($downloadedImageList, $remoteImage->name, '');
  20. if(!empty($downloadedImage)) continue;
  21. $remoteImage->status = 'notDownloaded';
  22. $remoteImage->from = 'zentao';
  23. $remoteImage->osName = $remoteImage->os;
  24. $remoteImage->host = $hostID;
  25. $this->dao->insert(TABLE_IMAGE)->data($remoteImage, 'desc,os')->autoCheck()->exec();
  26. $refreshPageData = true;
  27. }
  28. return $refreshPageData;
  29. }
  30. /**
  31. * 获取当前的下载任务。
  32. * Get current download task.
  33. *
  34. * @param int $imageID
  35. * @param object $statusGroupTasks
  36. * @access protected
  37. * @return null|object
  38. */
  39. protected function getCurrentTask($imageID, $statusGroupTasks)
  40. {
  41. $currentTask = null;
  42. $finished = false;
  43. foreach($statusGroupTasks as $groupTasks)
  44. {
  45. if($finished) break;
  46. foreach($groupTasks as $task)
  47. {
  48. if($finished) break;
  49. if($task->task != $imageID) continue;
  50. $task->endDate = $task->endDate ? substr($task->endDate, 0, 19) : '';
  51. if(empty($currentTask) || strtotime($task->endDate) > strtotime($currentTask->endDate)) $currentTask = $task;
  52. if($task->status == 'inprogress')
  53. {
  54. $currentTask = $task;
  55. $finished = true;
  56. break;
  57. }
  58. }
  59. }
  60. return $currentTask;
  61. }
  62. }