/** * synchronize a Variation of a Cluster-Instance with the Cluster-Template. * @param integer Cluster-ID, i.e. ID of the Variation. */ function syncCluster($clid) { global $db; $syncList = null; // determine cluster-node. $cln = getDBCell("cluster_variations", "CLNID", "CLID = {$clid}"); // determine cluster-template. $clt = getDBCell("cluster_node", "CLT_ID", "CLNID = {$cln}"); // get a list with the configuration of the cluster... $sql = "SELECT CLTI_ID, NAME, MINCARD, MAXCARD, FKID, CLTITYPE_ID FROM cluster_template_items WHERE CLT_ID = {$clt} AND DELETED=0 AND FKID <> 0 ORDER BY POSITION"; $cltis = new query($db, $sql); while ($cltis->getrow()) { $cltiId = $cltis->field("CLTI_ID"); $name = $cltis->field("NAME"); $mincard = $cltis->field("MINCARD"); $maxcard = $cltis->field("MAXCARD"); $type = $cltis->field("CLTITYPE_ID"); $fkid = $cltis->field("FKID"); // check, if enough fields are present. $syncSQL = "SELECT COUNT(CLCID) AS ANZ FROM cluster_content WHERE CLID = {$clid} AND CLTI_ID = {$cltiId} AND DELETED = 0"; $syncQuery = new query($db, $syncSQL); $syncQuery->getrow(); $amount = $syncQuery->field("ANZ"); if ($amount < $mincard) { // we must(!) syncronize as there are not enough fields. $newpos = 1; $maxposSQL = "SELECT MAX(POSITION) AS MPOS FROM cluster_content WHERE CLTI_ID = {$cltiId} AND CLID = {$clid}"; $mq = new query($db, $maxposSQL); if ($mq->getrow()) { $newpos = $mq->field("MPOS") + 1; } $mq->free(); if ($type == 2) { // dynamic content item. while ($amount < $mincard) { $nextId = $db->nextid("GUID"); $ssql = "INSERT INTO cluster_content (CLCID, CLID, CLTI_ID, POSITION, TITLE, FKID, DELETED) VALUES "; $ssql .= "({$nextId}, {$clid}, {$cltiId}, {$newpos}, '', 0,0)"; $synq = new query($db, $ssql); $amount++; $newpos++; $nextsync = count($syncList); $syncList[$nextsync][0] = $nextId; $syncList[$nextsync][1] = $fkid; } } else { if ($type == 4 || $type == 6) { //dynamic cluster item. Create slots. while ($amount < $mincard) { $nextId = $db->nextid("GUID"); $ssql = "INSERT INTO cluster_content (CLCID, CLID, CLTI_ID, POSITION, TITLE, FKID, DELETED) VALUES "; $ssql .= "({$nextId}, {$clid}, {$cltiId}, {$newpos}, '', 0,0)"; $synq = new query($db, $ssql); $amount++; $newpos++; } } else { if ($type == 5) { //library content. Create slots. while ($amount < $mincard) { $nextId = $db->nextid("GUID"); $ssql = "INSERT INTO cluster_content (CLCID, CLID, CLTI_ID, POSITION, TITLE, FKID, DELETED) VALUES "; $ssql .= "({$nextId}, {$clid}, {$cltiId}, {$newpos}, '', 0,0)"; $synq = new query($db, $ssql); $amount++; $newpos++; } } else { if ($type == 8) { //channel. Create empty slots. while ($amount < $mincard) { $nextId = nextGUID(); $ssql = "INSERT INTO cluster_content (CLCID, CLID, CLTI_ID, POSITION, TITLE, FKID, DELETED) VALUES "; $ssql .= "({$nextId}, {$clid}, {$cltiId}, {$newpos}, '', 0,0)"; $synq = new query($db, $ssql); $amount++; $newpos++; createCenterstage($nextId); } } } } } } /*if ($amount > $maxcard) { // there is nothing to be done. This check is to be performed when // launching a cluster and therefore an error has to be prompted! }*/ } // traverse through synclist; $counter = 0; while (count($syncList) > $counter) { $PGNRef = createPGNRef($syncList[$counter][1], $syncList[$counter][0]); if ($PGNRef != null) { $PGNRef->sync(); } //syncMetas($syncList[$counter][0], "CLUSTERCONTENT"); //reactivate for having meta on each cluter-item... $counter++; } }
/** * Create references for new content. * @param integer ID of the content to create. */ function createReferencedItem($id) { createCenterstage($id); }