Page MenuHomestyx hydra

No OneTemporary

diff --git a/resources/sql/autopatches/20180306.opath.03.purge.php b/resources/sql/autopatches/20180306.opath.03.purge.php
new file mode 100644
index 0000000000..91a15e2a58
--- /dev/null
+++ b/resources/sql/autopatches/20180306.opath.03.purge.php
@@ -0,0 +1,22 @@
+<?php
+
+$table = new PhabricatorOwnersPath();
+$conn = $table->establishConnection('w');
+
+$seen = array();
+foreach (new LiskMigrationIterator($table) as $path) {
+ $package_id = $path->getPackageID();
+ $repository_phid = $path->getRepositoryPHID();
+ $path_index = $path->getPathIndex();
+
+ if (!isset($seen[$package_id][$repository_phid][$path_index])) {
+ $seen[$package_id][$repository_phid][$path_index] = true;
+ continue;
+ }
+
+ queryfx(
+ $conn,
+ 'DELETE FROM %T WHERE id = %d',
+ $table->getTableName(),
+ $path->getID());
+}
diff --git a/resources/sql/autopatches/20180306.opath.04.unique.sql b/resources/sql/autopatches/20180306.opath.04.unique.sql
new file mode 100644
index 0000000000..2349533b1f
--- /dev/null
+++ b/resources/sql/autopatches/20180306.opath.04.unique.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_owners.owners_path
+ ADD UNIQUE KEY `key_path` (packageID, repositoryPHID, pathIndex);
diff --git a/src/applications/owners/storage/PhabricatorOwnersPath.php b/src/applications/owners/storage/PhabricatorOwnersPath.php
index 47f7faa2b3..7e7822df1a 100644
--- a/src/applications/owners/storage/PhabricatorOwnersPath.php
+++ b/src/applications/owners/storage/PhabricatorOwnersPath.php
@@ -1,117 +1,118 @@
<?php
final class PhabricatorOwnersPath extends PhabricatorOwnersDAO {
protected $packageID;
protected $repositoryPHID;
protected $pathIndex;
protected $path;
protected $excluded;
private $fragments;
private $fragmentCount;
protected function getConfiguration() {
return array(
self::CONFIG_TIMESTAMPS => false,
self::CONFIG_COLUMN_SCHEMA => array(
'path' => 'text255',
'pathIndex' => 'bytes12',
'excluded' => 'bool',
),
self::CONFIG_KEY_SCHEMA => array(
- 'packageID' => array(
- 'columns' => array('packageID'),
+ 'key_path' => array(
+ 'columns' => array('packageID', 'repositoryPHID', 'pathIndex'),
+ 'unique' => true,
),
),
) + parent::getConfiguration();
}
public static function newFromRef(array $ref) {
$path = new PhabricatorOwnersPath();
$path->repositoryPHID = $ref['repositoryPHID'];
$raw_path = $ref['path'];
$path->pathIndex = PhabricatorHash::digestForIndex($raw_path);
$path->path = $raw_path;
$path->excluded = $ref['excluded'];
return $path;
}
public function getRef() {
return array(
'repositoryPHID' => $this->getRepositoryPHID(),
'path' => $this->getPath(),
'excluded' => (int)$this->getExcluded(),
);
}
public static function getTransactionValueChanges(array $old, array $new) {
return array(
self::getTransactionValueDiff($old, $new),
self::getTransactionValueDiff($new, $old),
);
}
private static function getTransactionValueDiff(array $u, array $v) {
$set = self::getSetFromTransactionValue($v);
foreach ($u as $key => $ref) {
if (self::isRefInSet($ref, $set)) {
unset($u[$key]);
}
}
return $u;
}
public static function getSetFromTransactionValue(array $v) {
$set = array();
foreach ($v as $ref) {
$set[$ref['repositoryPHID']][$ref['path']][$ref['excluded']] = true;
}
return $set;
}
public static function isRefInSet(array $ref, array $set) {
return isset($set[$ref['repositoryPHID']][$ref['path']][$ref['excluded']]);
}
/**
* Get the number of directory matches between this path specification and
* some real path.
*/
public function getPathMatchStrength($path_fragments, $path_count) {
$this_path = $this->path;
if ($this_path === '/') {
// The root path "/" just matches everything with strength 1.
return 1;
}
if ($this->fragments === null) {
$this->fragments = PhabricatorOwnersPackage::splitPath($this_path);
$this->fragmentCount = count($this->fragments);
}
$self_fragments = $this->fragments;
$self_count = $this->fragmentCount;
if ($self_count > $path_count) {
// If this path is longer (and therefore more specific) than the target
// path, we don't match it at all.
return 0;
}
for ($ii = 0; $ii < $self_count; $ii++) {
if ($self_fragments[$ii] != $path_fragments[$ii]) {
return 0;
}
}
return $self_count;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jul 3, 5:44 PM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
166130
Default Alt Text
(4 KB)

Event Timeline