public function testUpsertWithFieldsSpecifiedInWackyOrder() { $userRc = $this->registry->schema->getResourceClass('user'); $newUsers = $this->storage->saveItems(array(array('username' => 'Bob Dylan', 'passhash' => 'asd123')), $userRc, array(EarthIT_Storage_ItemSaver::RETURN_SAVED => true, EarthIT_Storage_ItemSaver::ON_DUPLICATE_KEY => EarthIT_Storage_ItemSaver::ODK_UPDATE)); $newUsers = self::keyById($newUsers); $bob = EarthIT_Storage_Util::first($newUsers); $fixedUsers = $this->storage->saveItems(array(array('passhash' => 'asdf1234', 'ID' => $bob['ID'], 'username' => 'Bob Marley')), $userRc, array(EarthIT_Storage_ItemSaver::RETURN_SAVED => true, EarthIT_Storage_ItemSaver::ON_DUPLICATE_KEY => EarthIT_Storage_ItemSaver::ODK_UPDATE)); $fetchedUsers = $this->storage->searchItems(EarthIT_Storage_Util::makeSearch($userRc, array('ID' => $bob['ID']))); $this->assertEquals(array('ID' => $bob['ID'], 'passhash' => 'asdf1234', 'username' => 'Bob Marley', 'e-mail address' => null), EarthIT_Storage_Util::first($fetchedUsers)); }
/** * TODO: Document how different stuffs get parsed. */ public static function parseMulti($filters, EarthIT_Schema_ResourceClass $rc, EarthIT_Schema $schema = null, $fuzzyMatch = false) { if ($filters === '') { return self::emptyFilter(); } if ($filters instanceof EarthIT_Storage_ItemFilter) { return $filters; } if (is_string($filters)) { $filters = array_map('urldecode', explode('&', $filters)); } if (!is_array($filters)) { throw new Exception("'\$filters' parameter must be a string, an array, or an ItemFilter."); } foreach ($filters as $k => &$f) { if (is_string($k)) { //$f = "{$k}={$f}"; // ['ID' => 'foo'] = ['ID=foo'] $f = self::parsePattern($k, $f, $rc, $schema, $fuzzyMatch); } else { $f = self::parse($f, $rc, $schema, $fuzzyMatch); } } unset($f); if (count($filters) == 1) { return EarthIT_Storage_Util::first($filters); } return new EarthIT_Storage_Filter_AndedItemFilter($filters); }