2011-04-03 23:48:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-03-14 00:21:04 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-04-03 23:48:36 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-03-14 00:21:04 +01:00
|
|
|
final class PhabricatorOwnersPackage extends PhabricatorOwnersDAO {
|
2011-04-03 23:48:36 +02:00
|
|
|
|
|
|
|
protected $phid;
|
|
|
|
protected $name;
|
Add Basic Auditing Functionalities
Summary:
add basic auditing functionalities. For the related commits for a
package, we detect the following conditions which might be suspicious to the
owners of the package:
* no revision specified
* revision not found
* author not match
* reviewedby not match
* owners not involved
* commit author not recognized
The owners of the package can change the status of the audit entries by
accepting it or specify concern.
The owner can turn on/off the auditing for a package.
Test Plan:
* verified that non-owner cannot see the details of the audit and cannot modify
it
* verified that all the audit reasons can be detected
* tested dropdown filtering and package search
* verified really normal change not detected
* verified accept/concern a commit
* tested enable/disable a package for auditing
* verified one audit applies to all <commit, packages> to the packages the
auditor owns
* verified that re-parsing a commit won't have effect if there exists a
relationship for <commit, package> already
Reviewers: epriestley, nh
Reviewed By: epriestley
CC: aran, benmathews, btrahan, mpodobnik, prithvi, TomL, epriestley
Differential Revision: 1242
2011-12-18 00:52:54 +01:00
|
|
|
protected $auditingEnabled;
|
2011-04-03 23:48:36 +02:00
|
|
|
protected $description;
|
|
|
|
protected $primaryOwnerPHID;
|
|
|
|
|
2011-04-04 07:03:27 +02:00
|
|
|
private $unsavedOwners;
|
|
|
|
private $unsavedPaths;
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
private $actorPHID;
|
|
|
|
private $oldPrimaryOwnerPHID;
|
|
|
|
private $oldAuditingEnabled;
|
2011-04-04 07:03:27 +02:00
|
|
|
|
2011-04-03 23:48:36 +02:00
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
// This information is better available from the history table.
|
|
|
|
self::CONFIG_TIMESTAMPS => false,
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
2011-04-04 07:03:27 +02:00
|
|
|
) + parent::getConfiguration();
|
2011-04-03 23:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
2011-04-04 07:03:27 +02:00
|
|
|
return PhabricatorPHID::generateNewPHID('OPKG');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachUnsavedOwners(array $owners) {
|
|
|
|
$this->unsavedOwners = $owners;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachUnsavedPaths(array $paths) {
|
|
|
|
$this->unsavedPaths = $paths;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
public function attachActorPHID($actor_phid) {
|
|
|
|
$this->actorPHID = $actor_phid;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getActorPHID() {
|
|
|
|
return $this->actorPHID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachOldPrimaryOwnerPHID($old_primary) {
|
|
|
|
$this->oldPrimaryOwnerPHID = $old_primary;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOldPrimaryOwnerPHID() {
|
|
|
|
return $this->oldPrimaryOwnerPHID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachOldAuditingEnabled($auditing_enabled) {
|
|
|
|
$this->oldAuditingEnabled = $auditing_enabled;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOldAuditingEnabled() {
|
|
|
|
return $this->oldAuditingEnabled;
|
|
|
|
}
|
|
|
|
|
2011-04-04 07:03:27 +02:00
|
|
|
public function loadOwners() {
|
|
|
|
if (!$this->getID()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
return id(new PhabricatorOwnersOwner())->loadAllWhere(
|
|
|
|
'packageID = %d',
|
|
|
|
$this->getID());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function loadPaths() {
|
|
|
|
if (!$this->getID()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
return id(new PhabricatorOwnersPath())->loadAllWhere(
|
|
|
|
'packageID = %d',
|
|
|
|
$this->getID());
|
|
|
|
}
|
|
|
|
|
2011-04-04 08:23:36 +02:00
|
|
|
public static function loadAffectedPackages(
|
|
|
|
PhabricatorRepository $repository,
|
|
|
|
array $paths) {
|
|
|
|
|
|
|
|
if (!$paths) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$fragments = array(
|
|
|
|
'/' => true,
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($paths as $path) {
|
2011-04-12 06:51:36 +02:00
|
|
|
$fragments += self::splitPath($path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::loadPackagesForPaths($repository, array_keys($fragments));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function loadOwningPackages($repository, $path) {
|
|
|
|
if (empty($path)) {
|
|
|
|
return array();
|
2011-04-04 08:23:36 +02:00
|
|
|
}
|
|
|
|
|
2011-04-12 06:51:36 +02:00
|
|
|
$fragments = self::splitPath($path);
|
|
|
|
return self::loadPackagesForPaths($repository, array_keys($fragments), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function loadPackagesForPaths(
|
|
|
|
PhabricatorRepository $repository,
|
|
|
|
array $paths,
|
|
|
|
$limit = 0) {
|
2011-04-04 08:23:36 +02:00
|
|
|
$package = new PhabricatorOwnersPackage();
|
|
|
|
$path = new PhabricatorOwnersPath();
|
2011-04-12 06:51:36 +02:00
|
|
|
$conn = $package->establishConnection('r');
|
|
|
|
|
|
|
|
$repository_clause = qsprintf($conn, 'AND p.repositoryPHID = %s',
|
|
|
|
$repository->getPHID());
|
|
|
|
|
|
|
|
$limit_clause = '';
|
|
|
|
if (!empty($limit)) {
|
|
|
|
$limit_clause = qsprintf($conn, 'LIMIT %d', $limit);
|
|
|
|
}
|
|
|
|
|
2011-04-04 08:23:36 +02:00
|
|
|
$data = queryfx_all(
|
2011-04-12 06:51:36 +02:00
|
|
|
$conn,
|
|
|
|
'SELECT pkg.id FROM %T pkg JOIN %T p ON p.packageID = pkg.id
|
|
|
|
WHERE p.path IN (%Ls) %Q ORDER BY LENGTH(p.path) DESC %Q',
|
2011-04-04 08:23:36 +02:00
|
|
|
$package->getTableName(),
|
|
|
|
$path->getTableName(),
|
2011-04-12 06:51:36 +02:00
|
|
|
$paths,
|
|
|
|
$repository_clause,
|
|
|
|
$limit_clause);
|
|
|
|
|
|
|
|
$ids = ipull($data, 'id');
|
2011-04-04 08:23:36 +02:00
|
|
|
|
2011-04-12 06:51:36 +02:00
|
|
|
if (empty($ids)) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$order = array();
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
if (empty($order[$id])) {
|
|
|
|
$order[$id] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$packages = $package->loadAllWhere('id in (%Ld)', array_keys($order));
|
|
|
|
|
2011-04-15 01:17:39 +02:00
|
|
|
$packages = array_select_keys($packages, array_keys($order));
|
2011-04-12 06:51:36 +02:00
|
|
|
|
2011-04-15 01:17:39 +02:00
|
|
|
return $packages;
|
2011-04-04 08:23:36 +02:00
|
|
|
}
|
|
|
|
|
2011-04-04 07:03:27 +02:00
|
|
|
public function save() {
|
|
|
|
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
if ($this->getID()) {
|
|
|
|
$is_new = false;
|
|
|
|
} else {
|
|
|
|
$is_new = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->openTransaction();
|
2011-04-04 07:03:27 +02:00
|
|
|
|
|
|
|
$ret = parent::save();
|
|
|
|
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
$add_owners = array();
|
|
|
|
$remove_owners = array();
|
|
|
|
$all_owners = array();
|
2011-04-04 07:03:27 +02:00
|
|
|
if ($this->unsavedOwners) {
|
|
|
|
$new_owners = array_fill_keys($this->unsavedOwners, true);
|
|
|
|
$cur_owners = array();
|
|
|
|
foreach ($this->loadOwners() as $owner) {
|
|
|
|
if (empty($new_owners[$owner->getUserPHID()])) {
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
$remove_owners[$owner->getUserPHID()] = true;
|
2011-04-04 07:03:27 +02:00
|
|
|
$owner->delete();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$cur_owners[$owner->getUserPHID()] = true;
|
|
|
|
}
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
|
2011-04-04 07:03:27 +02:00
|
|
|
$add_owners = array_diff_key($new_owners, $cur_owners);
|
2012-06-02 06:41:56 +02:00
|
|
|
$all_owners = array_merge(
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
array($this->getPrimaryOwnerPHID() => true),
|
|
|
|
$new_owners,
|
2012-06-02 06:41:56 +02:00
|
|
|
$remove_owners);
|
2011-04-04 07:03:27 +02:00
|
|
|
foreach ($add_owners as $phid => $ignored) {
|
|
|
|
$owner = new PhabricatorOwnersOwner();
|
|
|
|
$owner->setPackageID($this->getID());
|
|
|
|
$owner->setUserPHID($phid);
|
|
|
|
$owner->save();
|
|
|
|
}
|
|
|
|
unset($this->unsavedOwners);
|
|
|
|
}
|
|
|
|
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
$add_paths = array();
|
|
|
|
$remove_paths = array();
|
|
|
|
$touched_repos = array();
|
2011-04-04 07:03:27 +02:00
|
|
|
if ($this->unsavedPaths) {
|
|
|
|
$new_paths = igroup($this->unsavedPaths, 'repositoryPHID', 'path');
|
|
|
|
$cur_paths = $this->loadPaths();
|
|
|
|
foreach ($cur_paths as $key => $path) {
|
|
|
|
if (empty($new_paths[$path->getRepositoryPHID()][$path->getPath()])) {
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
$touched_repos[$path->getRepositoryPHID()] = true;
|
|
|
|
$remove_paths[$path->getRepositoryPHID()][$path->getPath()] = true;
|
2011-04-04 07:03:27 +02:00
|
|
|
$path->delete();
|
|
|
|
unset($cur_paths[$key]);
|
|
|
|
}
|
|
|
|
}
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
|
2011-04-04 07:03:27 +02:00
|
|
|
$cur_paths = mgroup($cur_paths, 'getRepositoryPHID', 'getPath');
|
|
|
|
foreach ($new_paths as $repository_phid => $paths) {
|
2011-12-21 01:23:24 +01:00
|
|
|
// get repository object for path validation
|
|
|
|
$repository = id(new PhabricatorRepository())->loadOneWhere(
|
|
|
|
'phid = %s',
|
|
|
|
$repository_phid);
|
|
|
|
if (!$repository) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-04-04 07:03:27 +02:00
|
|
|
foreach ($paths as $path => $ignored) {
|
2011-12-21 01:23:24 +01:00
|
|
|
$path = ltrim($path, '/');
|
|
|
|
// build query to validate path
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-20 03:52:14 +01:00
|
|
|
$drequest = DiffusionRequest::newFromDictionary(
|
2011-12-21 01:23:24 +01:00
|
|
|
array(
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-20 03:52:14 +01:00
|
|
|
'repository' => $repository,
|
|
|
|
'path' => $path,
|
2011-12-21 01:23:24 +01:00
|
|
|
));
|
|
|
|
$query = DiffusionBrowseQuery::newFromDiffusionRequest($drequest);
|
|
|
|
$query->needValidityOnly(true);
|
|
|
|
$valid = $query->loadPaths();
|
|
|
|
$is_directory = true;
|
|
|
|
if (!$valid) {
|
|
|
|
switch ($query->getReasonForEmptyResultSet()) {
|
|
|
|
case DiffusionBrowseQuery::REASON_IS_FILE:
|
|
|
|
$valid = true;
|
|
|
|
$is_directory = false;
|
|
|
|
break;
|
|
|
|
case DiffusionBrowseQuery::REASON_IS_EMPTY:
|
|
|
|
$valid = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($is_directory && substr($path, -1) != '/') {
|
|
|
|
$path .= '/';
|
|
|
|
}
|
2011-12-22 18:49:46 +01:00
|
|
|
if (substr($path, 0, 1) != '/') {
|
|
|
|
$path = '/'.$path;
|
|
|
|
}
|
2011-12-21 01:23:24 +01:00
|
|
|
if (empty($cur_paths[$repository_phid][$path]) && $valid) {
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
$touched_repos[$repository_phid] = true;
|
|
|
|
$add_paths[$repository_phid][$path] = true;
|
2011-04-04 07:03:27 +02:00
|
|
|
$obj = new PhabricatorOwnersPath();
|
|
|
|
$obj->setPackageID($this->getID());
|
|
|
|
$obj->setRepositoryPHID($repository_phid);
|
|
|
|
$obj->setPath($path);
|
|
|
|
$obj->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($this->unsavedPaths);
|
|
|
|
}
|
|
|
|
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
$this->saveTransaction();
|
|
|
|
|
|
|
|
if ($is_new) {
|
|
|
|
$mail = new PackageCreateMail($this);
|
|
|
|
} else {
|
|
|
|
$mail = new PackageModifyMail(
|
|
|
|
$this,
|
|
|
|
array_keys($add_owners),
|
|
|
|
array_keys($remove_owners),
|
|
|
|
array_keys($all_owners),
|
|
|
|
array_keys($touched_repos),
|
|
|
|
$add_paths,
|
|
|
|
$remove_paths);
|
|
|
|
}
|
|
|
|
$mail->send();
|
|
|
|
|
2011-04-04 07:03:27 +02:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete() {
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
$mails = id(new PackageDeleteMail($this))->prepareMails();
|
|
|
|
|
|
|
|
$this->openTransaction();
|
2011-04-04 07:03:27 +02:00
|
|
|
foreach ($this->loadOwners() as $owner) {
|
|
|
|
$owner->delete();
|
|
|
|
}
|
|
|
|
foreach ($this->loadPaths() as $path) {
|
|
|
|
$path->delete();
|
|
|
|
}
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
|
|
|
|
$ret = parent::delete();
|
|
|
|
|
|
|
|
$this->saveTransaction();
|
|
|
|
|
|
|
|
foreach ($mails as $mail) {
|
|
|
|
$mail->saveAndSend();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ret;
|
2011-04-03 23:48:36 +02:00
|
|
|
}
|
|
|
|
|
2011-04-12 06:51:36 +02:00
|
|
|
private static function splitPath($path) {
|
|
|
|
$result = array();
|
|
|
|
$trailing_slash = preg_match('@/$@', $path) ? '/' : '';
|
|
|
|
$path = trim($path, '/');
|
|
|
|
$parts = explode('/', $path);
|
|
|
|
while (count($parts)) {
|
|
|
|
$result['/'.implode('/', $parts).$trailing_slash] = true;
|
|
|
|
$trailing_slash = '/';
|
|
|
|
array_pop($parts);
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2011-04-03 23:48:36 +02:00
|
|
|
}
|