/** * Processes any meetings where the startDateTime is in the past and it has not been processed yet for * latestActivityDateTime. * * @see BaseJob::run() */ public function run() { $processed = 0; foreach (static::getModelsToProcess(self::$pageSize) as $meeting) { ContactLatestActivityDateTimeObserver::resolveRelatedModelsAndSetLatestActivityDateTime($meeting->activityItems, $meeting->startDateTime, 'Contact'); AccountLatestActivityDateTimeObserver::resolveRelatedModelsAndSetLatestActivityDateTime($meeting->activityItems, $meeting->startDateTime, 'Account'); $meeting->processedForLatestActivity = true; $saved = $meeting->save(); if (!$saved) { throw new FailedToSaveModelException(); } else { $processed++; } } $this->getMessageLogger()->addInfoMessage($this->resolveProcessedMessage($processed)); return true; }
public function testResolveRelatedContactsAndSetLatestActivityDateTime() { $contact = ContactTestHelper::createContactByNameForOwner('contact2', Yii::app()->user->userModel); $this->assertNull($contact->latestActivityDateTime); $contact2 = ContactTestHelper::createContactByNameForOwner('contact3', Yii::app()->user->userModel); $this->assertNull($contact2->latestActivityDateTime); $task = TaskTestHelper::createTaskByNameForOwner('task3', Yii::app()->user->userModel); $task->activityItems->add($contact); $task->activityItems->add($contact2); $this->assertTrue($task->save()); $this->assertNull($task->activityItems[0]->latestActivityDateTime); $this->assertNull($task->activityItems[1]->latestActivityDateTime); $taskId = $task->id; $contactId = $contact->id; $contact2Id = $contact2->id; $task->forget(); $contact->forget(); $contact2->forget(); //Retrieve the task, so the related activity item is an Item and needs to be casted down $task = Task::getById($taskId); $dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); ContactLatestActivityDateTimeObserver::resolveRelatedModelsAndSetLatestActivityDateTime($task->activityItems, $dateTime, 'Contact'); $task->forget(); $contact = Contact::getById($contactId); $this->assertEquals($dateTime, $contact->latestActivityDateTime); $contact2 = Contact::getById($contact2Id); $this->assertEquals($dateTime, $contact2->latestActivityDateTime); }