summaryrefslogtreecommitdiff
path: root/app/Model/ProjectPermission.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model/ProjectPermission.php')
-rw-r--r--app/Model/ProjectPermission.php28
1 files changed, 20 insertions, 8 deletions
diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php
index fc7ab0d5..0249b3b1 100644
--- a/app/Model/ProjectPermission.php
+++ b/app/Model/ProjectPermission.php
@@ -324,17 +324,29 @@ class ProjectPermission extends Base
/**
* Copy user access from a project to another one
*
- * @author Antonio Rabelo
- * @param integer $project_from Project Template
- * @return integer $project_to Project that receives the copy
+ * @param integer $project_src Project Template
+ * @return integer $project_dst Project that receives the copy
* @return boolean
*/
- public function duplicate($project_from, $project_to)
+ public function duplicate($project_src, $project_dst)
{
- $users = $this->getMembers($project_from);
-
- foreach ($users as $user_id => $name) {
- if (! $this->addMember($project_to, $user_id)) { // TODO: Duplicate managers
+ $rows = $this->db
+ ->table(self::TABLE)
+ ->columns('project_id', 'user_id', 'is_owner')
+ ->eq('project_id', $project_src)
+ ->findAll();
+
+ foreach ($rows as $row) {
+
+ $result = $this->db
+ ->table(self::TABLE)
+ ->save(array(
+ 'project_id' => $project_dst,
+ 'user_id' => $row['user_id'],
+ 'is_owner' => (int) $row['is_owner'], // (int) for postgres
+ ));
+
+ if (! $result) {
return false;
}
}