Example #1
0
 /** @group slow */
 public function testUpdater()
 {
     $countBeforeUpdate = (int) $this->db->execute('SELECT house_count FROM address_objects WHERE id = ?q', ['0c5b2444-70a0-4932-980c-b4dc0d3f02b5'])->fetchResult();
     $housesConfig = $this->container->getHousesImportConfig();
     $housesConfig['fields']['PREVIOUSID'] = ['name' => 'previous_id', 'type' => 'uuid'];
     $updater = new HousesUpdater($this->db, $housesConfig['table_name'], $housesConfig['fields']);
     $updater->update($this->reader);
     $this->assertEquals('02к123', $this->db->execute('SELECT full_number FROM houses WHERE house_id = ?q', ['a64330e3-7a41-41ee-a8a2-41db8693c584'])->fetchResult());
     $this->assertEquals('1к2с3', $this->db->execute('SELECT full_number FROM houses WHERE house_id = ?q', ['00000000-0000-0000-0000-000000000000'])->fetchResult());
     $this->assertEquals($countBeforeUpdate + 2, $this->db->execute('SELECT house_count FROM address_objects WHERE address_id = ?q', ['77303f7c-452b-4e73-b2b0-cbc59fe636c5'])->fetchResult());
 }
Example #2
0
}
$oldVersionId = UpdateLogHelper::getLastVersionId($db);
$newVersionId = $directory->getVersionId();
if ($newVersionId != $oldVersionId + 1) {
    throw new \LogicException("Попытка обновления с версии {$oldVersionId} на версию {$newVersionId}.");
}
$db->execute('SET CONSTRAINTS "address_objects_parent_id_fkey", "houses_parent_id_fkey" DEFERRED');
$housesConfig = $container->getHousesImportConfig();
$addressObjectsConfig = $container->getAddressObjectsImportConfig();
$deletedHouseFile = $directory->getDeletedHouseFile();
if ($deletedHouseFile && $housesConfig) {
    $houseRemover = new Remover($db, $housesConfig['table_name'], $housesConfig['xml_key'], $housesConfig['database_key']);
    $houseRemover->remove(new XmlReader($deletedHouseFile, $housesConfig['node_name'], [$housesConfig['primary_key']], []));
}
$deletedAddressObjectsFile = $directory->getDeletedAddressObjectFile();
if ($deletedAddressObjectsFile) {
    $addressObjectsRemover = new Remover($db, $addressObjectsConfig['table_name'], $addressObjectsConfig['xml_key'], $addressObjectsConfig['database_key']);
    $addressObjectsRemover->remove(new XmlReader($deletedAddressObjectsFile, $addressObjectsConfig['node_name'], [$addressObjectsConfig['xml_key']], []));
}
$addressObjectFields = $addressObjectsConfig['fields'];
$addressObjectFields['PREVID'] = ['name' => 'previous_id', 'type' => 'uuid'];
$addressObjectsUpdater = new AddressObjectsUpdater($db, $addressObjectsConfig['table_name'], $addressObjectFields);
$addressObjectsUpdater->update(new XmlReader($directory->getAddressObjectFile(), $addressObjectsConfig['node_name'], array_keys($addressObjectFields), $addressObjectsConfig['filters']));
if ($housesConfig) {
    $houseFields = $housesConfig['fields'];
    $houseFields['PREVID'] = ['name' => 'previous_id', 'type' => 'uuid'];
    $housesUpdater = new HousesUpdater($db, $housesConfig['table_name'], $houseFields);
    $housesUpdater->update(new XmlReader($directory->getHouseFile(), $housesConfig['node_name'], array_keys($houseFields), []));
}
UpdateLogHelper::addVersionIdToLog($db, $directory->getVersionId());
$db->commit();