This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, master has been updated
       via  ed738201b2c7adea668549578f0ce7bee72ae610 (commit)
      from  c94004b0dd15c825a18c81b4691a7047aae95123 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=ed738201b2c7adea668549578f0ce7bee72ae610

commit ed738201b2c7adea668549578f0ce7bee72ae610
Author: Stéphane-Eymeric Bredthauer <sebredtha...@gmail.com>
Date:   Mon Sep 19 12:01:44 2016 +0200

    Tracker: improve import 3

diff --git a/src/common/tracker/Artifact.class.php 
b/src/common/tracker/Artifact.class.php
index 96284c8..d59e637 100644
--- a/src/common/tracker/Artifact.class.php
+++ b/src/common/tracker/Artifact.class.php
@@ -278,7 +278,7 @@ class Artifact extends FFError {
                                // the changes to the extra fields will be 
logged in this array.
                                // (we won't use it however)
                                $extra_field_changes = array();
-                               if 
(!$this->updateExtraFields($extra_fields,$extra_field_changes)) {
+                               if (!$this->updateExtraFields($extra_fields, 
$extra_field_changes, $importData)) {
                                        db_rollback();
                                        return false;
                                }
@@ -762,6 +762,9 @@ class Artifact extends FFError {
         * @param       string  $body           The $string message being 
attached.
         * @param       bool    $by             Email $string address of 
message creator.
         * @param       bool    $send_followup  Whether $bool to email out a 
followup.
+        * @param       array   $importData     Array of data to change 
submitter and time of submit like:
+        *                                              array('user' => 127, 
'time' => 1234556789)
+        * 
         * @return      bool    success.
         */
        function addMessage($body,$by=false,$send_followup=false,$importData = 
array()) {
@@ -775,7 +778,8 @@ class Artifact extends FFError {
                }
                
                if(array_key_exists('user', $importData)){
-                               $user = user_get_object($importData['user']);
+                               $user_id = $importData['user'];
+                               $user = user_get_object($user_id);
                                if (!$user || !is_object($user)) {
                                        $this->setError('Error: Logged In User 
But Could Not Get User Object');
                                        return false;
@@ -812,7 +816,7 @@ class Artifact extends FFError {
                                               $time,
                                               htmlspecialchars($body))) ;
 
-               $this->updateLastModifiedDate();
+               $this->updateLastModifiedDate($importData);
 
                if ($send_followup) {
                        $this->mailFollowupEx($time, 2, false);
@@ -901,45 +905,57 @@ class Artifact extends FFError {
         * @param       int     $new_artifact_type_id   Allows you to move an 
artifact to another type.
         * @param       array   $extra_fields           Array of extra fields 
like: array(15=>'foobar',22=>'1');
         * @param       string  $description            The description.
+        * @param       array   $importData     Array of data to change 
submitter and time of submit like:
+        *                                              array('user' => 127, 
'time' => 1234556789)
         * @return      boolean success.
         */
        function update($priority,$status_id,
                
$assigned_to,$summary,$canned_response,$details,$new_artifact_type_id,
-               $extra_fields=array(), $description='') {
+               $extra_fields=array(), $description='', $importData=array()) {
 
+               if (array_key_exists('user', $importData)){
+                       $user = $importData['user'];
+               }
+               if (empty($importData)) {
+                       $isAnImport = false;
+               } else {
+                       $isAnImport = true;
+               }
                /*
                        Field-level permission checking
                */
-               if (!forge_check_perm ('tracker', $this->ArtifactType->getID(), 
'manager')) {
-                       // Non-managers cannot modify these fields
-                       $priority=$this->getPriority();
-                       $summary=htmlspecialchars_decode($this->getSummary());
-                       
$description=htmlspecialchars_decode($this->getDetails());
-                       $canned_response=100;
-                       $new_artifact_type_id=$this->ArtifactType->getID();
-                       $autoAssignField = 
$this->getArtifactType()->getAutoAssignField();
-                       if ($autoAssignField!=100) {
-                               $ef = new 
ArtifactExtraField($this->getArtifactType(),$autoAssignField);
-                               if (!$ef || !is_object($ef)) {
-                                       exit_error(_('Unable to create 
ArtifactExtraField Object'),'tracker');
-                               } elseif ($ef->isError()) {
-                                       
exit_error($ef->getErrorMessage(),'tracker');
-                               } else {
-                                       $efe = new 
ArtifactExtraFieldElement($ef,$extra_fields[$autoAssignField]);
-                                       if (!$efe || !is_object($efe)) {
-                                               exit_error(_('Unable to create 
ArtifactExtraFieldElement Object'),'tracker');
-                                       } elseif ($efe->isError()) {
-                                               
exit_error($efe->getErrorMessage(),'tracker');
+               if (!$isAnImport) { 
+                       if (!forge_check_perm ('tracker', 
$this->ArtifactType->getID(), 'manager')) {
+                               // Non-managers cannot modify these fields
+                               $priority=$this->getPriority();
+                               
$summary=htmlspecialchars_decode($this->getSummary());
+                               
$description=htmlspecialchars_decode($this->getDetails());
+                               $canned_response=100;
+                               
$new_artifact_type_id=$this->ArtifactType->getID();
+                               $autoAssignField = 
$this->getArtifactType()->getAutoAssignField();
+                               if ($autoAssignField!=100) {
+                                       $ef = new 
ArtifactExtraField($this->getArtifactType(),$autoAssignField);
+                                       if (!$ef || !is_object($ef)) {
+                                               exit_error(_('Unable to create 
ArtifactExtraField Object'),'tracker');
+                                       } elseif ($ef->isError()) {
+                                               
exit_error($ef->getErrorMessage(),'tracker');
                                        } else {
-                                               $assigned_to = 
$efe->getAutoAssignto();
+                                               $efe = new 
ArtifactExtraFieldElement($ef,$extra_fields[$autoAssignField]);
+                                               if (!$efe || !is_object($efe)) {
+                                                       exit_error(_('Unable to 
create ArtifactExtraFieldElement Object'),'tracker');
+                                               } elseif ($efe->isError()) {
+                                                       
exit_error($efe->getErrorMessage(),'tracker');
+                                               } else {
+                                                       $assigned_to = 
$efe->getAutoAssignto();
+                                               }
                                        }
+                               } else {
+                                       $assigned_to = $this->getAssignedTo();
+                               }
+                               if (!forge_check_perm ('tracker', 
$this->ArtifactType->getID(), 'tech')) {
+                                       $this->setPermissionDeniedError();
+                                       return false;
                                }
-                       } else {
-                               $assigned_to = $this->getAssignedTo();
-                       }
-                       if (!forge_check_perm ('tracker', 
$this->ArtifactType->getID(), 'tech')) {
-                               $this->setPermissionDeniedError();
-                               return false;
                        }
                }
                //
@@ -972,7 +988,7 @@ class Artifact extends FFError {
                }
 
                // Check that assigned_to is a tech for the tracker
-               if ($assigned_to != 100) {
+               if ($assigned_to != 100 && !$isAnImport) {
                        if (!forge_check_perm_for_user ($assigned_to, 
'tracker', $this->ArtifactType->getID(), 'tech')) {
                                $this->setError(_("Invalid assigned person: 
must be a technician"));
                                return false;
@@ -1002,7 +1018,7 @@ class Artifact extends FFError {
                                return false;
                        }
                        //      do they have perms for new ArtifactType?
-                       if (!forge_check_perm ('tracker', 
$newArtifactType->getID(), 'manager')) {
+                       if (!forge_check_perm ('tracker', 
$newArtifactType->getID(), 'manager') && !$isAnImport) {
                                $this->setPermissionDeniedError();
                                db_rollback();
                                return false;
@@ -1012,8 +1028,8 @@ class Artifact extends FFError {
                        $message = sprintf(_('Moved from %1$s to %2$s'),
                                $this->ArtifactType->getName(),
                                $newArtifactType->getName());
-                       $this->addHistory('type', 
$this->ArtifactType->getName());
-                       $this->addMessage($message,'',0);
+                       $this->addHistory('type', 
$this->ArtifactType->getName(), $importData);
+                       $this->addMessage($message,'',0, $importData);
 
                        // Fake change to send a mail when moved.
                        $changes['Type'] = 1;
@@ -1089,7 +1105,7 @@ class Artifact extends FFError {
                        }
 
                        // Check that assigned_to is a tech in the new tracker
-                       if ($assigned_to != 100) {
+                       if ($assigned_to != 100 && !$isAnImport) {
                                if (!forge_check_perm ('tracker', 
$newArtifactType->getID(), 'tech')) {
                                        $assigned_to = 100;
                                }
@@ -1107,47 +1123,52 @@ class Artifact extends FFError {
                //
                //      handle audit trail
                //
-               $now = time();
+               if (array_key_exists('time',$importData)){
+                       $time = $importData['time'];
+               } else {
+                       $time = time();
+               }
+               
                if ($this->getStatusID() != $status_id) {
-                       $this->addHistory('status_id',$this->getStatusID());
+                       $this->addHistory('status_id',$this->getStatusID(), 
$importData);
                        $qpa = db_construct_qpa($qpa, ' status_id=$1,', 
array($status_id));
                        $changes['status'] = 1;
                        $update = true;
 
                        if ($status_id != 1) {
-                               $qpa = db_construct_qpa($qpa, ' 
close_date=$1,', array($now));
+                               $qpa = db_construct_qpa($qpa, ' 
close_date=$1,', array($time));
                        } else {
                          $qpa = db_construct_qpa($qpa, ' close_date=$1,', 
array(0));
                        }
-                       $this->addHistory('close_date', $this->getCloseDate());
+                       $this->addHistory('close_date', $this->getCloseDate(), 
$importData);
                }
                if ($this->getPriority() != $priority) {
-                       $this->addHistory('priority',$this->getPriority());
+                       $this->addHistory('priority',$this->getPriority(), 
$importData);
                        $qpa = db_construct_qpa($qpa, ' priority=$1,', 
array($priority));
                        $changes['priority'] = 1;
                        $update = true;
                }
 
                if ($this->getAssignedTo() != $assigned_to) {
-                       $this->addHistory('assigned_to',$this->getAssignedTo());
+                       $this->addHistory('assigned_to',$this->getAssignedTo(), 
$importData);
                        $qpa = db_construct_qpa($qpa, ' assigned_to=$1,', 
array($assigned_to));
                        $changes['assigned_to'] = 1;
                        $update = true;
                }
                if ($summary && ($this->getSummary() != 
htmlspecialchars($summary))) {
-                       $this->addHistory('summary', $this->getSummary());
+                       $this->addHistory('summary', $this->getSummary(), 
$importData);
                        $qpa = db_construct_qpa($qpa, ' summary=$1,', 
array(htmlspecialchars($summary)));
                        $changes['summary'] = 1;
                        $update = true;
                }
                if ($description && ($this->getDetails() != 
htmlspecialchars($description))) {
-                       $this->addHistory('details', $this->getDetails());
+                       $this->addHistory('details', $this->getDetails(), 
$importData);
                        $qpa = db_construct_qpa($qpa, ' details=$1,', 
array(htmlspecialchars($description)));
                        $changes['details'] = 1;
                        $update = true;
                }
                if ($details) {
-                       $this->addMessage($details,'',0);
+                       $this->addMessage($details, '' ,0 , $importData);
                        $changes['details'] = 1;
                        $send_message=true;
                }
@@ -1176,7 +1197,7 @@ class Artifact extends FFError {
 
                //extra field handling
                $update=true;
-               if (!$this->updateExtraFields($extra_fields,$changes)) {
+               if (!$this->updateExtraFields($extra_fields, $changes, 
$importData)) {
 //TODO - see if anything actually did change
                        db_rollback();
                        return false;
@@ -1197,7 +1218,7 @@ class Artifact extends FFError {
                        } else {
                                $body = $acr->getBody();
                                if ($body) {
-                                       if 
(!$this->addMessage(util_unconvert_htmlspecialchars($body),'',0)) {
+                                       if 
(!$this->addMessage(util_unconvert_htmlspecialchars($body),'',0,$importData)) {
                                                db_rollback();
                                                return false;
                                        } else {
@@ -1213,7 +1234,7 @@ class Artifact extends FFError {
                if ($update || $send_message){
                        if (!empty($changes)) {
                                // Send the email with changes
-                               $this->mailFollowupEx($now, 2, false, $changes);
+                               $this->mailFollowupEx($time, 2, false, 
$changes);
                        }
                        db_commit();
                        return true;
@@ -1228,12 +1249,19 @@ class Artifact extends FFError {
 
        /**
         * updateLastModifiedDate - update the last_modified_date attribute of 
this artifact.
+        * @param       array   $importData     Array of data to change 
submitter and time of submit like:
+        *                                              array('user' => 127, 
'time' => 1234556789)
         *
         * @return      bool    true on success / false on failure
         */
-       function updateLastModifiedDate() {
-               $res = db_query_params ('UPDATE artifact SET 
last_modified_date=EXTRACT(EPOCH FROM now())::integer WHERE artifact_id=$1',
-                       array ($this->getID()));
+       function updateLastModifiedDate($importData = array()) {
+               if (array_key_exists('time',$importData)){
+                       $time = $importData['time'];
+               } else {
+                       $time = time();
+               }
+               $res = db_query_params ('UPDATE artifact SET 
last_modified_date=$1 WHERE artifact_id=$2',
+                       array ($time, $this->getID()));
                return (!$res);
        }
 
@@ -1266,9 +1294,12 @@ class Artifact extends FFError {
         *
         * @param       array   Array of extra fields like: 
array(15=>'foobar',22=>'1');
         * @param       array   Array where changes to the extra fields should 
be logged
+        * @param       array   Array of data to change submitter and time of 
submit like:
+        *                                              array('user' => 127, 
'time' => 1234556789)
+        * 
         * @return      bool    true on success / false on failure
         */
-       function updateExtraFields($extra_fields,&$changes){
+       function updateExtraFields($extra_fields, &$changes, $importData = 
array()){
 /*
        This is extremely complex code - we have take the passed array
        and see if we need to insert it into the db, and may have to
@@ -1284,6 +1315,11 @@ class Artifact extends FFError {
                                skip it and continue to next item
 
 */
+               if (empty($importData)) {
+                       $isAnImport = false;
+               } else {
+                       $isAnImport = true;
+               }
                $update = false;
 
                //get a list of extra fields for this artifact_type
@@ -1298,7 +1334,7 @@ class Artifact extends FFError {
 
                // If there is a status field, then check against the workflow.
                // Unless if we change type.
-               if (! isset($changes['Type']) || !$changes['Type']) {
+               if ((!isset($changes['Type']) || !$changes['Type']) && 
!$isAnImport) {
                        for ($i=0; $i<count($efk); $i++) {
                                $efid=$efk[$i];
                                $type=$ef[$efid]['field_type'];
@@ -1336,7 +1372,7 @@ class Artifact extends FFError {
                        $type=$ef[$efid]['field_type'];
 
                        // check required fields
-                       if ($ef[$efid]['is_required'] || in_array($efid, $rf)) {
+                       if (($ef[$efid]['is_required'] || in_array($efid, $rf)) 
&& !$isAnImport) {
                                if (!array_key_exists($efid, $extra_fields)) {
                                        if ($type == 
ARTIFACT_EXTRAFIELDTYPE_STATUS) {
                                                $this->setError(_('Status 
Custom Field Must Be Set'));
@@ -1372,10 +1408,11 @@ class Artifact extends FFError {
                        }
 
                        // check parent field
-                       if ($type == ARTIFACT_EXTRAFIELDTYPE_SELECT ||
+                       if (($type == ARTIFACT_EXTRAFIELDTYPE_SELECT ||
                                        $type == 
ARTIFACT_EXTRAFIELDTYPE_MULTISELECT ||
                                        $type == ARTIFACT_EXTRAFIELDTYPE_RADIO 
||
-                                       $type == 
ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) {
+                                       $type == 
ARTIFACT_EXTRAFIELDTYPE_CHECKBOX)
+                                       && !$isAnImport) {
                                $allowed = false;
                                if (!is_null($ef[$efid]['parent']) && 
!empty($ef[$efid]['parent']) && $ef[$efid]['parent']!='100') {
                                        $aefParentId = $ef[$efid]['parent'];
@@ -1409,7 +1446,11 @@ class Artifact extends FFError {
 
 
                        // check pattern for text fields
-                       if ($type == ARTIFACT_EXTRAFIELDTYPE_TEXT && 
!empty($ef[$efid]['pattern']) && !empty($extra_fields[$efid]) && 
!preg_match('/'.$ef[$efid]['pattern'].'/', $extra_fields[$efid])) {
+                       if ($type == ARTIFACT_EXTRAFIELDTYPE_TEXT &&
+                                       !empty($ef[$efid]['pattern']) &&
+                                       !empty($extra_fields[$efid]) &&
+                                       
!preg_match('/'.$ef[$efid]['pattern'].'/', $extra_fields[$efid]) &&
+                                       !$isAnImport) {
                                $this->setError(sprintf(_("Field %s doesn't 
match the pattern."), $ef[$efid]['field_name']));
                                return false;
                        }
@@ -1581,7 +1622,7 @@ class Artifact extends FFError {
                unset($this->extra_field_data);
 
                if ($update)
-                       $this->updateLastModifiedDate();
+                       $this->updateLastModifiedDate($importData);
 
                return true;
        }

-----------------------------------------------------------------------

Summary of changes:
 src/common/tracker/Artifact.class.php | 157 +++++++++++++++++++++-------------
 1 file changed, 99 insertions(+), 58 deletions(-)


hooks/post-receive
-- 
FusionForge

_______________________________________________
Fusionforge-commits mailing list
Fusionforge-commits@lists.fusionforge.org
http://lists.fusionforge.org/cgi-bin/mailman/listinfo/fusionforge-commits

Reply via email to