示例#1
0
 /**
  * Saves one builder element at a time on project edit.
  */
 public static function project_integrationBuilderSaveElement()
 {
     /*
     matamouros 2011.05.18:
     In order to simpflify a great deal of things, I've opted for the following:
         . filesets in HTML are abstracted as seamlessly part of the respective
           tasks where they are used. In truth, filesets should be completely
           independent editable forms, and tasks should then reference them
           (perhaps on a select dropdown).
         . The above means that, for now, only one fileset is allowed for
           each task that uses it.
     Alas, this simplification accounts for slightly bloatier code in
         this method, namely because we now have to special case the processing
         of seamless embedded filesets and make sure that backstage they are
         still properly updating the corresponding Build_BuilderElement_Fileset object.
     */
     SystemEvent::raise(SystemEvent::DEBUG, "Called.", __METHOD__);
     if (empty($GLOBALS['project']) || !$GLOBALS['project'] instanceof Project || empty($_REQUEST['internalId'])) {
         $msg = 'Invalid request';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         echo json_encode(array('success' => false, 'error' => $msg));
         exit;
     }
     if (!$GLOBALS['project']->userHasAccessLevel($GLOBALS['user'], Access::WRITE) && !$GLOBALS['user']->hasCos(UserCos::ROOT)) {
         $msg = 'Not authorized';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         echo json_encode(array('success' => false, 'error' => $msg));
         exit;
     }
     $o = $GLOBALS['project']->getIntegrationBuilder()->getElement($_REQUEST['internalId']['value']);
     if (!$o instanceof Build_BuilderElement) {
         $msg = 'Unknown task specified';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         echo json_encode(array('success' => false, 'error' => $msg));
         exit;
     }
     if (!$o->isEditable()) {
         $msg = 'Builder element not editable';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         echo json_encode(array('success' => false, 'error' => $msg));
         exit;
     }
     foreach ($_REQUEST as $attributeName => $attributeValue) {
         $method = 'set' . ucfirst($attributeName);
         if (!isset($attributeValue['value'])) {
             // Unselected radio buttons cause the value attribute to not be sent
             $attributeValue['value'] = null;
         }
         $value = filter_var($attributeValue['value'], FILTER_SANITIZE_STRING);
         if ($attributeValue['type'] == 'checkbox') {
             $value = !empty($attributeValue['value']) ? true : false;
         }
         //
         // Specific handling for filesets
         //
         if (($attributeName == 'include' || $attributeName == 'exclude' || $attributeName == 'defaultExcludes' || $attributeName == 'dir' || $attributeName == 'type') && ($o instanceof Build_BuilderElement_Task_Perl_PerlSyntax || $o instanceof Build_BuilderElement_Task_Php_PhpUnit || $o instanceof Build_BuilderElement_Task_Php_PhpLint || $o instanceof Build_BuilderElement_Task_Filesystem_Chmod || $o instanceof Build_BuilderElement_Task_Filesystem_Chown || $o instanceof Build_BuilderElement_Task_Filesystem_Delete || $o instanceof Build_BuilderElement_Task_Filesystem_Copy || $o instanceof Build_BuilderElement_Task_ReplaceRegexp)) {
             $filesets = $o->getFilesets();
             // Only one is expected, for now
             if ($attributeName == 'include' || $attributeName == 'exclude') {
                 $value = array($value);
             } elseif ($attributeName == 'type' && $value != Build_BuilderElement_Type_Fileset::BOTH && $value != Build_BuilderElement_Type_Fileset::FILE && $value != Build_BuilderElement_Type_Fileset::DIR) {
                 $value = Build_BuilderElement_Type_Fileset::getDefaultType();
             }
             $filesets[0]->{$method}($value);
         } else {
             $o->{$method}($value);
         }
     }
     $GLOBALS['project']->log("Integration builder changed.", $GLOBALS['user']->getUsername());
     SystemEvent::raise(SystemEvent::DEBUG, "Builder element properly edited.", __METHOD__);
     echo json_encode(array('success' => true));
     exit;
 }