src/snac/server/ServerExecutor.php
/**
     * Compute Constellation Diff
     *
     * Given two Constellation IDs in the input, this method reads the current version of both constellations
     * out of the database.  If they are both published, a diff of the Constellations are computed.  All data
     * components unique to Constellation 1 are returned in the "this" object; all data components unique to
     * Constellation 2 are returned in the "other" object; and all data components shared by both Constellations
     * are returned in the "intersection" object.
     *
     * If the optional parameter `$startMerge` is set to true (default is false), then this method will try to
     * check out both constellations to the current user.  User permissions to actually be able to check out the
     * Constellations is checked in the Server main code.
     *
     * @param string[] $input Input array from the Server object
     * @param boolean $startMerge optional If true, will try to check out the constellations to the user to start a merge.
     * @throws \snac\exceptions\SNACInputException
     * @throws \snac\exceptions\SNACDatabaseException
     * @return string[] The response to send to the client
     */
Compute Constellation Diff
Given two Constellation IDs in the input, this method reads the current version of both constellations
out of the database.  If they are both published, a diff of the Constellations are computed.

If the optional parameter `$startMerge` is set to true (default is false), then this method will try to
check out both constellations to the current user.  User permissions to actually be able to check out the
Constellations is checked in the Server main code.

@param string[] $input Input array from the Server object
@param boolean $startMerge optional If true, will try to check out the constellations to the user to start a merge.
Compute Constellation Diff Given two Constellation IDs in the input this method reads the current version of both constellations out of the database . If they are both published a diff of the Constellations are computed . If the optional parameter ` $startMerge ` is set to true ( default is false ) then this method will try to check out both constellations to the current user . User permissions to actually be able to check out the Constellations is checked in the Server main code . @param string [] $input Input array from the Server object @param boolean $startMerge optional If true will try to check out the constellations to the user to start a merge .
public function diffConstellations(&$input, $startMerge=false) {
        $response = array();
        $this->logger->addDebug("Diffing constellations");
        if (isset($input["constellationid1"]) && isset($input["constellationid1"])) {
            try {
                $cId1 = $input["constellationid1"];
                $cId2 = $input["constellationid2"];
                $cV1 = null;
                if (isset($input["version1"]))
                    $cV1 = $input["version1"];
                $cId2 = $input["constellationid2"];
                $cV2 = null;
                if (isset($input["version2"]))
                    $cV2 = $input["version2"];
                $mergeable = $this->isMergeable($cId1, $cId2, $cV1, $cV2);
                if ($mergeable === true) {
                    $response["mergeable"] = true;
                    if ($startMerge === true) {
                        $this->logger->addDebug("User is requesting to diff the constellations for a merge");
                        $success1 = $this->cStore->writeConstellationStatus($this->user, $cId1, "currently editing");
                        if ($success1 === false) {
                            $this->logger->addError("Writing Constellation Status failed", array("user"=>$this->user, "id"=>$cId1));
                            throw new \snac\exceptions\SNACDatabaseException("Could not open the Constellation $cId1 for Editing", 403);
                        }
                        $success2 = $this->cStore->writeConstellationStatus($this->user, $cId2, "currently editing");
                        if ($success2 === false) {
                            $this->logger->addError("Writing Constellation Status failed", array("user"=>$this->user, "id"=>$cId2));
                            if ($success1 === true) {
                                $this->logger->addDebug("re-publishing to unlock constellation");
                                $result = $this->cStore->writeConstellationStatus($this->user, $cId1,
                                                "published", "Republish: An error occurred when trying to merge");
                                $this->updateIndexesAfterPublish($cId1);
                            }
                            throw new \snac\exceptions\SNACDatabaseException("Could not open the Constellation $cId2 for Editing", 403);
                        }
                    }
                } else {
                    $response["mergeable"] = false;
                    if ($mergeable !== null) {
                        $response["assertion"] = $mergeable->toArray();
                    }
                }
                $this->logger->addDebug("Reading Constellations from the database");
                $constellation1 = $this->cStore->readConstellation($cId1, $cV1, \snac\server\database\DBUtil::$FULL_CONSTELLATION);
                $constellation2 = $this->cStore->readConstellation($cId2, $cV2, \snac\server\database\DBUtil::$FULL_CONSTELLATION);
                $this->logger->addDebug("Starting Diff");
                $diffParts = $constellation1->diff($constellation2);
                $this->logger->addDebug("Finished Diff");
                if ($diffParts["this"] !== null)
                    $response["constellation1"] = $diffParts["this"]->toArray();
                else
                    $response["constellation1"] = null;
                if ($diffParts["other"] !== null)
                    $response["constellation2"] = $diffParts["other"]->toArray();
                else
                    $response["constellation2"] = null;
                if ($diffParts["intersection"] !== null)
                    $response["intersection"] = $diffParts["intersection"]->toArray();
                else {
                    $c = new \snac\data\Constellation();
                    $response["intersection"] = $c->toArray();
                }
            } catch (\Exception $e) {
                throw $e;
            }
        } else {
            throw new \snac\exceptions\SNACInputException("Diff requires two constellation IDs", 400);
        }
        return $response;
    }
public function diffConstellations ( & $ input , $ startMerge = false ) { $ response = array ( ) ; $ this -> logger -> addDebug ( " Diffing constellations " ) ; if ( isset ( $ input [ " constellationid1 " ] ) && isset ( $ input [ " constellationid1 " ] ) ) { try { $ cId1 = $ input [ " constellationid1 " ] ; $ cId2 = $ input [ " constellationid2 " ] ; $ cV1 = null ; if ( isset ( $ input [ " version1 " ] ) ) $ cV1 = $ input [ " version1 " ] ; $ cId2 = $ input [ " constellationid2 " ] ; $ cV2 = null ; if ( isset ( $ input [ " version2 " ] ) ) $ cV2 = $ input [ " version2 " ] ; $ mergeable = $ this -> isMergeable ( $ cId1 , $ cId2 , $ cV1 , $ cV2 ) ; if ( $ mergeable === true ) { $ response [ " mergeable " ] = true ; if ( $ startMerge === true ) { $ this -> logger -> addDebug ( " User is requesting to diff the constellations for a merge " ) ; $ success1 = $ this -> cStore -> writeConstellationStatus ( $ this -> user , $ cId1 , " currently editing " ) ; if ( $ success1 === false ) { $ this -> logger -> addError ( " Writing Constellation Status failed " , array ( " user " => $ this -> user , " id " => $ cId1 ) ) ; throw new \ snac \ exceptions \ SNACDatabaseException ( " Could not open the Constellation  $ cId1  for Editing " , 403 ) ; } $ success2 = $ this -> cStore -> writeConstellationStatus ( $ this -> user , $ cId2 , " currently editing " ) ; if ( $ success2 === false ) { $ this -> logger -> addError ( " Writing Constellation Status failed " , array ( " user " => $ this -> user , " id " => $ cId2 ) ) ; if ( $ success1 === true ) { $ this -> logger -> addDebug ( " re-publishing to unlock constellation " ) ; $ result = $ this -> cStore -> writeConstellationStatus ( $ this -> user , $ cId1 , " published " , " Republish: An error occurred when trying to merge " ) ; $ this -> updateIndexesAfterPublish ( $ cId1 ) ; } throw new \ snac \ exceptions \ SNACDatabaseException ( " Could not open the Constellation  $ cId2  for Editing " , 403 ) ; } } } else { $ response [ " mergeable " ] = false ; if ( $ mergeable !== null ) { $ response [ " assertion " ] = $ mergeable -> toArray ( ) ; } } $ this -> logger -> addDebug ( " Reading Constellations from the database " ) ; $ constellation1 = $ this -> cStore -> readConstellation ( $ cId1 , $ cV1 , \ snac \ server \ database \ DBUtil :: $ FULL_CONSTELLATION ) ; $ constellation2 = $ this -> cStore -> readConstellation ( $ cId2 , $ cV2 , \ snac \ server \ database \ DBUtil :: $ FULL_CONSTELLATION ) ; $ this -> logger -> addDebug ( " Starting Diff " ) ; $ diffParts = $ constellation1 -> diff ( $ constellation2 ) ; $ this -> logger -> addDebug ( " Finished Diff " ) ; if ( $ diffParts [ " this " ] !== null ) $ response [ " constellation1 " ] = $ diffParts [ " this " ] -> toArray ( ) ; else $ response [ " constellation1 " ] = null ; if ( $ diffParts [ " other " ] !== null ) $ response [ " constellation2 " ] = $ diffParts [ " other " ] -> toArray ( ) ; else $ response [ " constellation2 " ] = null ; if ( $ diffParts [ " intersection " ] !== null ) $ response [ " intersection " ] = $ diffParts [ " intersection " ] -> toArray ( ) ; else { $ c = new \ snac \ data \ Constellation ( ) ; $ response [ " intersection " ] = $ c -> toArray ( ) ; } } catch ( \ Exception $ e ) { throw $ e ; } } else { throw new \ snac \ exceptions \ SNACInputException ( " Diff requires two constellation IDs " , 400 ) ; } return $ response ; }
Compute Constellation Diff
 Given two Constellation IDs in the input, this method reads the current version of both constellations
 out of the database.
Compute Constellation Diff Given two Constellation IDs in the input this method reads the current version of both constellations out of the database .
// If two constellations were given // Right now, only published constellations can be merged, so that we can keep a "clean" history // If they asked to start the merge, then check these constellations out to that user as // CURRENTLY EDITING.  This is the same level of modification as doing an edit, so we don't // want the user to be able to open them for editing unless they unlock them. // lock the constellation to the user as currently editing // Must unlock the first constellation if the second one failed // Leaving a catch block for logging purposes