public function testMassUpdateNameId() { $contact = $this->contact('testAnyone'); // First, need to break all the nameIds... Contacts::model()->updateAll(array('nameId' => null)); // Try with the mass update method, one ID: X2Model::massUpdateNameId('Contacts', array($contact->id)); $contact->refresh(); $this->assertEquals(Fields::nameId($contact->name, $contact->id), $contact->nameId); // Again, but with the "ids" parameter an int instead of an array X2Model::massUpdateNameId('Contacts', $contact->id); $contact->refresh(); $this->assertEquals(Fields::nameId($contact->name, $contact->id), $contact->nameId); // Try again, multiple records: $contact2 = $this->contact('testUser'); Contacts::model()->updateAll(array('nameId' => null)); X2Model::massUpdateNameId('Contacts', array($contact->id, $contact2->id)); $contact->refresh(); $contact2->refresh(); $this->assertEquals(Fields::nameId($contact->name, $contact->id), $contact->nameId); $this->assertEquals(Fields::nameId($contact2->name, $contact2->id), $contact2->nameId); // Try one last time, all records: Contacts::model()->updateAll(array('nameId' => null)); X2Model::massUpdateNameId('Contacts'); $contact->refresh(); $contact2->refresh(); $this->assertEquals(Fields::nameId($contact->name, $contact->id), $contact->nameId); $this->assertEquals(Fields::nameId($contact2->name, $contact2->id), $contact2->nameId); }
/** * Populate the nameId field since auto-populating fields is * disabled and it is far more efficient to do it in a single query */ protected function massUpdateImportedNameIds($importedIds, $type) { $hasNameId = Fields::model()->findByAttributes(array('fieldName' => 'nameId', 'modelName' => $type)); if ($hasNameId) { X2Model::massUpdateNameId($type, $importedIds); } }