Christopher Johnson (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/185973

Change subject: adds new ProjectCustomField "IsSprint" that replaces special 
character
......................................................................

adds new ProjectCustomField "IsSprint" that replaces special character

changes validation logic for other custom fields to show or not show

Bug: 87229
Change-Id: Iefa14e4740939b7e5b7dbe7f86a8cda87eab0f35
---
M src/__phutil_library_map__.php
M src/constants/SprintConstants.php
A src/customfield/SprintIsSprintField.php
M src/customfield/SprintProjectCustomField.php
M src/customfield/SprintTaskStoryPointsField.php
M src/query/SprintQuery.php
M src/util/SprintValidator.php
7 files changed, 112 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/phabricator/extensions/Sprint 
refs/changes/73/185973/1

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
index eaa98ee..29d86aa 100644
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -49,6 +49,7 @@
     'SprintEndDateField' => 'customfield/SprintEndDateField.php',
     'SprintFactDaemon' => 'fact/SprintFactDaemon.php',
     'SprintFactUpdateIterator' => 'fact/SprintFactUpdateIterator.php',
+    'SprintIsSprintField' => 'customfield/SprintIsSprintField.php',
     'SprintListController' => 'controller/SprintListController.php',
     'SprintPoints' => 'util/SprintPoints.php',
     'SprintProjectCustomField' => 'customfield/SprintProjectCustomField.php',
@@ -102,6 +103,7 @@
     'SprintEndDateField' => 'SprintProjectCustomField',
     'SprintFactDaemon' => 'PhabricatorDaemon',
     'SprintFactUpdateIterator' => 'PhutilBufferedIterator',
+    'SprintIsSprintField' => 'SprintProjectCustomField',
     'SprintListController' => 'SprintController',
     'SprintProjectCustomField' => array(
       'PhabricatorProjectCustomField',
diff --git a/src/constants/SprintConstants.php 
b/src/constants/SprintConstants.php
index 4a78fd1..6324bd8 100644
--- a/src/constants/SprintConstants.php
+++ b/src/constants/SprintConstants.php
@@ -8,4 +8,5 @@
   const LIBPHUTIL_ROOT_DIR = 'vendor/libphutil/libphutil';
   const ROOT_DIR = '/srv/phab';
   const CUSTOMFIELD_INDEX = 'yERhvoZPNPtM';
+  const SPRINTFIELD_INDEX = 'scsOmkpB9Tqi';
 } 
\ No newline at end of file
diff --git a/src/customfield/SprintIsSprintField.php 
b/src/customfield/SprintIsSprintField.php
new file mode 100644
index 0000000..61dcb57
--- /dev/null
+++ b/src/customfield/SprintIsSprintField.php
@@ -0,0 +1,36 @@
+<?php
+
+final class SprintIsSprintField extends SprintProjectCustomField {
+
+  private $field_proxy;
+
+  public function __construct() {
+    $this->field_proxy = $this->getBoolFieldProxy($this, 
$this->getFieldName(), $this->getFieldDescription());
+  }
+
+  // == General field identity stuff
+  public function getFieldKey() {
+    return 'isdc:sprint:issprint';
+  }
+
+  public function getFieldName() {
+    return 'Is Sprint';
+  }
+
+  public function getFieldDescription() {
+    return 'Project Is Sprint';
+  }
+
+  public function renderPropertyViewValue(array $handles) {
+    return $this->renderBoolProxyPropertyViewValue($this->field_proxy, 
$handles);
+  }
+
+  public function renderEditControl(array $handles) {
+    return $this->field_proxy->renderEditControl($handles);
+  }
+
+  // == Search
+  public function shouldAppearInApplicationSearch() {
+    return true;
+  }
+}
diff --git a/src/customfield/SprintProjectCustomField.php 
b/src/customfield/SprintProjectCustomField.php
index 8654ea7..615ea0d 100644
--- a/src/customfield/SprintProjectCustomField.php
+++ b/src/customfield/SprintProjectCustomField.php
@@ -11,7 +11,7 @@
   protected function isSprint() {
     $validator = new SprintValidator;
     $is_sprint = call_user_func(array($validator, 'checkForSprint'),
-        array($validator, 'shouldShowSprintFields'), $this->getObject());
+        array($validator, 'isSprint'), $this->getObject()->getPHID());
     return $is_sprint;
   }
 
@@ -39,6 +39,27 @@
     return $date_proxy;
   }
 
+  /**
+   * @param string $name
+   * @param string $description
+   */
+  public function getBoolFieldProxy($field, $name, $description) {
+    $obj = clone $field;
+    $field_proxy = id(new PhabricatorStandardCustomFieldBool())
+        ->setFieldKey($this->getFieldKey())
+        ->setApplicationField($obj)
+        ->setFieldConfig(array(
+            'name' => $name,
+            'description' => $description,
+        ));
+    $this->setProxy($field_proxy);
+    return $field_proxy;
+  }
+
+  public function renderBoolProxyPropertyViewValue($bool_proxy, $handles) {
+      return $bool_proxy->renderPropertyViewValue($handles);
+  }
+
   public function renderDateProxyPropertyViewValue($date_proxy, $handles) {
     $is_sprint = $this->isSprint();
 
diff --git a/src/customfield/SprintTaskStoryPointsField.php 
b/src/customfield/SprintTaskStoryPointsField.php
index e1cc69f..c671de5 100644
--- a/src/customfield/SprintTaskStoryPointsField.php
+++ b/src/customfield/SprintTaskStoryPointsField.php
@@ -65,18 +65,12 @@
       if (empty($project_phids)) {
         return $show = false;
       }
-      // Fetch the names from all the Projects associated with this task
-      $projects = id(new PhabricatorProject())
-        ->loadAllWhere(
-        'phid IN (%Ls)',
-        $project_phids);
-      $names = mpull($projects, 'getName');
 
-      // Set show to true if one of the Projects contains "Sprint"
       $show = false;
-      foreach($names as $name) {
-        if (strpos($name, SprintConstants::MAGIC_WORD) !== false) {
+      foreach ($project_phids as $project_phid) {
+        if ($this->isSprint($project_phid)) {
           $show = true;
+          break;
         }
       }
     }
@@ -84,25 +78,21 @@
   }
 
   public function renderPropertyViewLabel() {
-    if (!$this->showField()) {
-      return null;
+    if ($this->showField() === true) {
+      if ($this->text_proxy) {
+        return $this->text_proxy->renderPropertyViewLabel();
+      }
+      return $this->getFieldName();
     }
-
-    if ($this->text_proxy) {
-      return $this->text_proxy->renderPropertyViewLabel();
-    }
-    return $this->getFieldName();
   }
 
   public function renderPropertyViewValue(array $handles) {
-    if (!$this->showField()) {
-      return null;
+    if ($this->showField() === true) {
+      if ($this->text_proxy) {
+        return $this->text_proxy->renderPropertyViewValue($handles);
+      }
+      throw new PhabricatorCustomFieldImplementationIncompleteException($this);
     }
-
-    if ($this->text_proxy) {
-      return $this->text_proxy->renderPropertyViewValue($handles);
-    }
-    throw new PhabricatorCustomFieldImplementationIncompleteException($this);
   }
 
   public function shouldAppearInEditView() {
@@ -110,20 +100,24 @@
   }
 
   public function renderEditControl(array $handles) {
-    if (!$this->showField()) {
-      return null;
+    if ($this->showField() === true) {
+      if ($this->text_proxy) {
+        return $this->text_proxy->renderEditControl($handles);
+      }
+      throw new PhabricatorCustomFieldImplementationIncompleteException($this);
     }
-
-    if ($this->text_proxy) {
-      return $this->text_proxy->renderEditControl($handles);
-    }
-    throw new PhabricatorCustomFieldImplementationIncompleteException($this);
   }
 
   // == Search
-  public function shouldAppearInApplicationSearch()
-  {
+  public function shouldAppearInApplicationSearch() {
     return true;
   }
 
+  protected function isSprint($project_phid) {
+    $validator = new SprintValidator();
+    $is_sprint = call_user_func(array($validator, 'checkForSprint'),
+        array($validator, 'isSprint'), $project_phid);
+    return $is_sprint;
+  }
+
 }
diff --git a/src/query/SprintQuery.php b/src/query/SprintQuery.php
index e627eab..80c3075 100644
--- a/src/query/SprintQuery.php
+++ b/src/query/SprintQuery.php
@@ -78,6 +78,20 @@
     return $points;
   }
 
+  public function getIsSprint() {
+    $object = new PhabricatorProjectCustomFieldStorage();
+    $boolfield = $object->loadRawDataWhere('objectPHID= %s AND
+    fieldIndex=%s', $this->project_phid, SprintConstants::SPRINTFIELD_INDEX);
+    if (!empty($boolfield)) {
+      foreach ($boolfield as $array) {
+        $issprint = idx($array, 'fieldValue');
+      }
+    } else {
+      $issprint = null;
+    }
+    return $issprint;
+  }
+
   public function getXactions($tasks) {
     $task_phids = mpull($tasks, 'getPHID');
     $xactions = id(new ManiphestTransactionQuery())
diff --git a/src/util/SprintValidator.php b/src/util/SprintValidator.php
index 1ac0fc4..34461ef 100644
--- a/src/util/SprintValidator.php
+++ b/src/util/SprintValidator.php
@@ -2,9 +2,9 @@
 
 final class SprintValidator {
 
-  public function checkForSprint($showfields, $project) {
-    $show = $showfields($project);
-    if ($show === false) {
+  public function checkForSprint($showfields, $project_phid) {
+    $show = $showfields($project_phid);
+    if ($show == false) {
       return false;
     } else {
       return true;
@@ -14,4 +14,11 @@
   public function shouldShowSprintFields($project) {
     return (stripos($project->getName(), SprintConstants::MAGIC_WORD));
   }
-}
\ No newline at end of file
+
+  public function isSprint($project_phid) {
+    $query = id(new SprintQuery())
+        ->setPHID($project_phid);
+    $issprint = $query->getIsSprint();
+    return $issprint;
+  }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/185973
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iefa14e4740939b7e5b7dbe7f86a8cda87eab0f35
Gerrit-PatchSet: 1
Gerrit-Project: phabricator/extensions/Sprint
Gerrit-Branch: master
Gerrit-Owner: Christopher Johnson (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to