tmgmt.controller.job.inc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @file
  4. * Contains the job entity controller class.
  5. */
  6. /**
  7. * Controller class for the job entity.
  8. *
  9. * @ingroup tmgmt_job
  10. */
  11. class TMGMTJobController extends EntityAPIController {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function save($entity, DatabaseTransaction $transaction = NULL) {
  16. $entity->changed = REQUEST_TIME;
  17. return parent::save($entity, $transaction);
  18. }
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function delete($ids, $transaction = NULL) {
  23. parent::delete($ids, $transaction);
  24. // Since we are deleting one or multiple jobs here we also need to delete
  25. // the attached job items and messages.
  26. $query = new EntityFieldQuery();
  27. $result = $query->entityCondition('entity_type', 'tmgmt_job_item')
  28. ->propertyCondition('tjid', $ids)
  29. ->execute();
  30. if (!empty($result['tmgmt_job_item'])) {
  31. $controller = entity_get_controller('tmgmt_job_item');
  32. // We need to directly query the entity controller so we can pass on
  33. // the transaction object.
  34. $controller->delete(array_keys($result['tmgmt_job_item']), $transaction);
  35. }
  36. $query = new EntityFieldQuery();
  37. $result = $query->entityCondition('entity_type', 'tmgmt_message')
  38. ->propertyCondition('tjid', $ids)
  39. ->execute();
  40. if (!empty($result['tmgmt_message'])) {
  41. $controller = entity_get_controller('tmgmt_message');
  42. // We need to directly query the entity controller so we can pass on
  43. // the transaction object.
  44. $controller->delete(array_keys($result['tmgmt_message']), $transaction);
  45. }
  46. $query = new EntityFieldQuery();
  47. $result = $query->entityCondition('entity_type', 'tmgmt_remote')
  48. ->propertyCondition('tjid', $ids)
  49. ->execute();
  50. if (!empty($result['tmgmt_remote'])) {
  51. $controller = entity_get_controller('tmgmt_remote');
  52. $controller->delete(array_keys($result['tmgmt_remote']), $transaction);
  53. }
  54. }
  55. }