src/snac/server/ServerExecutor.php
/**
     * Automatically Merge Constellations
     *
     * Merges constellations automatically, when given a list of ICIDs to merge
     * together.  The User must have the permissions to edit the constellations
     * and publish them in order to complete the merge.
     *
     * @param string[] $input Input array from the Server object
     * @throws \snac\exceptions\SNACPermissionException
     * @throws \snac\exceptions\SNACInputException
     * @throws \snac\exceptions\SNACDatabaseException
     * @return string[] The response to send to the client
     */
Automatically Merge Constellations
Merges constellations automatically, when given a list of ICIDs to merge
together.  The User must have the permissions to edit the constellations
and publish them in order to complete the merge.


Automatically Merge Constellations Merges constellations automatically when given a list of ICIDs to merge together . The User must have the permissions to edit the constellations and publish them in order to complete the merge .
function autoMergeConstellations(&$input) {
        $response = array();
        $this->logger->addDebug("Merging constellations");
        if (isset($input["constellationids"]) && is_array($input["constellationids"])) {
            if (count($input["constellationids"]) < 2) {
                throw new \snac\exceptions\SNACInputException("Must merge at least 2 Constellations", 400);
            }
            $info = array();
            foreach ($input["constellationids"] as $cId) {
                if (!is_numeric($cId)) {
                    throw new \snac\exceptions\SNACInputException("Constellation ID $cId is not correctly formatted", 400);
                }
                $info[$cId] = $this->cStore->readConstellationUserStatus($cId);
                if (!is_array($info[$cId])) {
                    throw new \snac\exceptions\SNACInputException("Constellation $cId does not have a current version", 404);
                }
                if (($info[$cId]["status"] == "published") ||
                        ($info[$cId]["status"] == "locked editing" && $this->user->getUserID() == $info[$cId]["userid"])) {
                    $success = $this->cStore->writeConstellationStatus($this->user, $cId, "currently editing");
                    if ($success) {
                        $info[$cId] = $this->cStore->readConstellationUserStatus($cId);
                    }
                }
                if ($info[$cId]["status"] != "currently editing" || $this->user->getUserID() !== $info[$cId]["userid"]) {
                    throw new \snac\exceptions\SNACPermissionException("User trying to merge constellations not checked out to them", 400);
                }
            }
            $originals = array();
            foreach ($input["constellationids"] as $cId) {
                $originals[$cId] = $this->cStore->readConstellation($cId, null,
                    \snac\server\database\DBUtil::$FULL_CONSTELLATION);
                $this->logger->addDebug("Merging from", $originals[$cId] ? $originals[$cId]->toArray() : []);
            }
            $constellation = new \snac\data\Constellation();
            $constellation->setOperation(\snac\data\AbstractData::$OPERATION_INSERT);
            foreach ($originals as $c) {
                $constellation->combine($c);
            }
            $this->logger->addDebug("Auto-Merged Constellation is ", $constellation->toArray());
            return $this->coreMerge($constellation, $originals);
        } else {
            throw new \snac\exceptions\SNACInputException("Auto merge requires at least two constellation IDs", 400);
        }
    }
function autoMergeConstellations ( & $ input ) { $ response = array ( ) ; $ this -> logger -> addDebug ( " Merging constellations " ) ; if ( isset ( $ input [ " constellationids " ] ) && is_array ( $ input [ " constellationids " ] ) ) { if ( count ( $ input [ " constellationids " ] ) < 2 ) { throw new \ snac \ exceptions \ SNACInputException ( " Must merge at least 2 Constellations " , 400 ) ; } $ info = array ( ) ; foreach ( $ input [ " constellationids " ] as $ cId ) { if ( ! is_numeric ( $ cId ) ) { throw new \ snac \ exceptions \ SNACInputException ( " Constellation ID  $ cId  is not correctly formatted " , 400 ) ; } $ info [ $ cId ] = $ this -> cStore -> readConstellationUserStatus ( $ cId ) ; if ( ! is_array ( $ info [ $ cId ] ) ) { throw new \ snac \ exceptions \ SNACInputException ( " Constellation  $ cId  does not have a current version " , 404 ) ; } if ( ( $ info [ $ cId ] [ " status " ] == " published " ) || ( $ info [ $ cId ] [ " status " ] == " locked editing " && $ this -> user -> getUserID ( ) == $ info [ $ cId ] [ " userid " ] ) ) { $ success = $ this -> cStore -> writeConstellationStatus ( $ this -> user , $ cId , " currently editing " ) ; if ( $ success ) { $ info [ $ cId ] = $ this -> cStore -> readConstellationUserStatus ( $ cId ) ; } } if ( $ info [ $ cId ] [ " status " ] != " currently editing " || $ this -> user -> getUserID ( ) !== $ info [ $ cId ] [ " userid " ] ) { throw new \ snac \ exceptions \ SNACPermissionException ( " User trying to merge constellations not checked out to them " , 400 ) ; } } $ originals = array ( ) ; foreach ( $ input [ " constellationids " ] as $ cId ) { $ originals [ $ cId ] = $ this -> cStore -> readConstellation ( $ cId , null , \ snac \ server \ database \ DBUtil :: $ FULL_CONSTELLATION ) ; $ this -> logger -> addDebug ( " Merging from " , $ originals [ $ cId ] ? $ originals [ $ cId ] -> toArray ( ) : [ ] ) ; } $ constellation = new \ snac \ data \ Constellation ( ) ; $ constellation -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_INSERT ) ; foreach ( $ originals as $ c ) { $ constellation -> combine ( $ c ) ; } $ this -> logger -> addDebug ( " Auto-Merged Constellation is  " , $ constellation -> toArray ( ) ) ; return $ this -> coreMerge ( $ constellation , $ originals ) ; } else { throw new \ snac \ exceptions \ SNACInputException ( " Auto merge requires at least two constellation IDs " , 400 ) ; } }
Automatically Merge Constellations
 Merges constellations automatically, when given a list of ICIDs to merge
 together.
Automatically Merge Constellations Merges constellations automatically when given a list of ICIDs to merge together .
// Only able to merge if the status is published OR locked editing to this user // Try to check out the constellation.  If it doesn't work, then we will cancel it // TODOX // We have multiple constellation ids that should be merged and the "merged" copy of the constellation // ACTUALLY DOING THE MERGING STEPS IN THE SYSTEM // Read full to-be-merged constellations // Combine all the constellations into one