src/snac/server/ServerExecutor.php
/**
     * Write Constellation
     *
     * Uses DBUtil to write a constellation (from the input) in the database.  If no operation is set on the
     * Constellation, it returns a success as if it wrote, but without modifying the database.
     *
     * @param string[] $input Input array from the Server object
     * @throws \snac\exceptions\SNACException
     * @return string[] The response to send to the client
     */
Write Constellation
Uses DBUtil to write a constellation (from the input) in the database.  If no operation is set on the
Constellation, it returns a success as if it wrote, but without modifying the database.

@param string[] $input Input array from the Server object
@throws \snac\exceptions\SNACException
@return string[] The response to send to the client
Write Constellation Uses DBUtil to write a constellation ( from the input ) in the database . If no operation is set on the Constellation it returns a success as if it wrote but without modifying the database . @param string [] $input Input array from the Server object @throws \ snac \ exceptions \ SNACException @return string [] The response to send to the client
public function writeConstellation(&$input) {
        $response = array();
        if (isset($input["constellation"])) {
            $constellation = new \snac\data\Constellation($input["constellation"]);
            $this->logger->addDebug("Writing Constellation Data", $input["constellation"]);
            $this->logger->addDebug("Writing Constellation toArray", $constellation->toArray());
            try {
                $validation = new \snac\server\validation\ValidationEngine();
                $hasOperationValidator = new \snac\server\validation\validators\HasOperationValidator();
                $validation->addValidator($hasOperationValidator);
                $validation->addValidator(new \snac\server\validation\validators\ResourceValidator());
                $success = $validation->validateConstellation($constellation);
            } catch (\snac\exceptions\SNACValidationException $e) {
                $response["constellation"] = $constellation->toArray();
                $response["result"] = "success";
                return $response;
            }
            try {
                if (isset($input["constellation"])) {
                    $result = null;
                    $saveLog = null;
                    if (isset($input["message"]) && $input["message"] != null && $input["message"] != "")
                        $saveLog = $input["message"];
                    if ($constellation->getID() != null) {
                        $this->logger->addDebug("Constellation had an ID, so we're doing an update", array($constellation->getID()));
                        $inList = false;
                        $userList = $this->cStore->listConstellationsWithStatusForUser($this->user, "currently editing");
                        foreach ($userList as $item) {
                            if ($item->getID() == $constellation->getID() && $item->getVersion() == $constellation->getVersion()) {
                                $inList = true;
                                break;
                            }
                        }
                        if ($saveLog == null)
                            $saveLog = "Edits in Web UI";
                        if ($inList)
                            $result = $this->cStore->writeConstellation($this->user, $constellation, $saveLog);
                    } else {
                        $this->logger->addDebug("Writing a new constellation");
                        if ($saveLog == null)
                            $saveLog = "New Constellation from Web UI";
                        $result = $this->cStore->writeConstellation($this->user, $constellation, $saveLog);
                        if ($result != null) {
                            $version = $this->cStore->writeConstellationStatus($this->user, $result->getID(),
                                    "currently editing", "New constellation is already in edit");
                            if ($version !== false)
                                $result->setVersion($version);
                        } else {
                            $this->logger->addDebug("Couldn't write the new constellation for some reason");
                            $response["result"] = "failure";
                            $response["error"] = "an unknown error occurred while trying to write";
                            return $response;
                        }
                    }
                    if (isset($result) && $result != null) {
                        $this->logger->addDebug("successfully wrote constellation");
                        $response["constellation"] = $result->toArray();
                        $response["result"] = "success";
                    } else {
                        $this->logger->addDebug("writeConstellation returned a null result or edits not allowed");
                        $response["result"] = "failure";
                        $response["error"] = "this version is not the current version, other edits have happened";
                    }
                }
            } catch (\Exception $e) {
                $this->logger->addError("writeConstellation threw an exception");
                throw $e;
            }
        } else {
            $this->logger->addDebug("Constellation input value wasn't set to write");
            $response["result"] = "failure";
            $response["error"] = "no constellation to write";
        }
        return $response;
    }
public function writeConstellation ( & $ input ) { $ response = array ( ) ; if ( isset ( $ input [ " constellation " ] ) ) { $ constellation = new \ snac \ data \ Constellation ( $ input [ " constellation " ] ) ; $ this -> logger -> addDebug ( " Writing Constellation Data " , $ input [ " constellation " ] ) ; $ this -> logger -> addDebug ( " Writing Constellation toArray " , $ constellation -> toArray ( ) ) ; try { $ validation = new \ snac \ server \ validation \ ValidationEngine ( ) ; $ hasOperationValidator = new \ snac \ server \ validation \ validators \ HasOperationValidator ( ) ; $ validation -> addValidator ( $ hasOperationValidator ) ; $ validation -> addValidator ( new \ snac \ server \ validation \ validators \ ResourceValidator ( ) ) ; $ success = $ validation -> validateConstellation ( $ constellation ) ; } catch ( \ snac \ exceptions \ SNACValidationException $ e ) { $ response [ " constellation " ] = $ constellation -> toArray ( ) ; $ response [ " result " ] = " success " ; return $ response ; } try { if ( isset ( $ input [ " constellation " ] ) ) { $ result = null ; $ saveLog = null ; if ( isset ( $ input [ " message " ] ) && $ input [ " message " ] != null && $ input [ " message " ] != " " ) $ saveLog = $ input [ " message " ] ; if ( $ constellation -> getID ( ) != null ) { $ this -> logger -> addDebug ( " Constellation had an ID, so we're doing an update " , array ( $ constellation -> getID ( ) ) ) ; $ inList = false ; $ userList = $ this -> cStore -> listConstellationsWithStatusForUser ( $ this -> user , " currently editing " ) ; foreach ( $ userList as $ item ) { if ( $ item -> getID ( ) == $ constellation -> getID ( ) && $ item -> getVersion ( ) == $ constellation -> getVersion ( ) ) { $ inList = true ; break ; } } if ( $ saveLog == null ) $ saveLog = " Edits in Web UI " ; if ( $ inList ) $ result = $ this -> cStore -> writeConstellation ( $ this -> user , $ constellation , $ saveLog ) ; } else { $ this -> logger -> addDebug ( " Writing a new constellation " ) ; if ( $ saveLog == null ) $ saveLog = " New Constellation from Web UI " ; $ result = $ this -> cStore -> writeConstellation ( $ this -> user , $ constellation , $ saveLog ) ; if ( $ result != null ) { $ version = $ this -> cStore -> writeConstellationStatus ( $ this -> user , $ result -> getID ( ) , " currently editing " , " New constellation is already in edit " ) ; if ( $ version !== false ) $ result -> setVersion ( $ version ) ; } else { $ this -> logger -> addDebug ( " Couldn't write the new constellation for some reason " ) ; $ response [ " result " ] = " failure " ; $ response [ " error " ] = " an unknown error occurred while trying to write " ; return $ response ; } } if ( isset ( $ result ) && $ result != null ) { $ this -> logger -> addDebug ( " successfully wrote constellation " ) ; $ response [ " constellation " ] = $ result -> toArray ( ) ; $ response [ " result " ] = " success " ; } else { $ this -> logger -> addDebug ( " writeConstellation returned a null result or edits not allowed " ) ; $ response [ " result " ] = " failure " ; $ response [ " error " ] = " this version is not the current version, other edits have happened " ; } } } catch ( \ Exception $ e ) { $ this -> logger -> addError ( " writeConstellation threw an exception " ) ; throw $ e ; } } else { $ this -> logger -> addDebug ( " Constellation input value wasn't set to write " ) ; $ response [ " result " ] = " failure " ; $ response [ " error " ] = " no constellation to write " ; } return $ response ; }
Write Constellation
 Uses DBUtil to write a constellation (from the input) in the database.
Write Constellation Uses DBUtil to write a constellation ( from the input ) in the database .
// If the Constellation has no changes, then don't do anything and allow the "update" // but don't do anything // Get the message, if the client supplied one // If the constellation has an ID, then we should check that it's actually checked-out to the user // and the user is currently editing it! // Read the constellation summary and make sure the last version matches the current version // if they match, write, else send failure back with note about updating old version // If the constellation does not currently have and ID, then we should write it and have it checked // out to the user that wrote it.  Also, update the status to be currently editing // Rethrow it, since we just wanted a log statement