3 $interface_table = new AlmanacInterface();
4 $binding_table = new AlmanacBinding();
5 $interface_conn = $interface_table->establishConnection('w');
9 'LOCK TABLES %T WRITE, %T WRITE',
10 $interface_table->getTableName(),
11 $binding_table->getTableName());
14 foreach (new LiskMigrationIterator($interface_table) as $interface) {
15 $device = $interface->getDevicePHID();
16 $network = $interface->getNetworkPHID();
17 $address = $interface->getAddress();
18 $port = $interface->getPort();
19 $key = "{$device}/{$network}/{$address}/{$port}";
21 // If this is the first copy of this row we've seen, mark it as seen and
23 if (empty($seen[$key])) {
24 $seen[$key] = $interface->getID();
28 $survivor = queryfx_one(
30 'SELECT * FROM %T WHERE id = %d',
31 $interface_table->getTableName(),
34 $bindings = queryfx_all(
36 'SELECT * FROM %T WHERE interfacePHID = %s',
37 $binding_table->getTableName(),
38 $interface->getPHID());
40 // Repoint bindings to the survivor.
41 foreach ($bindings as $binding) {
42 // Check if there's already a binding to the survivor.
43 $existing = queryfx_one(
45 'SELECT * FROM %T WHERE interfacePHID = %s and devicePHID = %s and '.
47 $binding_table->getTableName(),
49 $binding['devicePHID'],
50 $binding['servicePHID']);
53 // Reattach this binding to the survivor.
56 'UPDATE %T SET interfacePHID = %s WHERE id = %d',
57 $binding_table->getTableName(),
61 // Binding to survivor already exists. Remove this now-redundant binding.
64 'DELETE FROM %T WHERE id = %d',
65 $binding_table->getTableName(),
72 'DELETE FROM %T WHERE id = %d',
73 $interface_table->getTableName(),
79 'ALTER TABLE %T ADD UNIQUE KEY `key_unique` '.
80 '(devicePHID, networkPHID, address, port)',
81 $interface_table->getTableName());