From b21291917bd276ae2d2c0194690901fc68aaf4fc Mon Sep 17 00:00:00 2001 From: Charlie Madison Date: Tue, 25 Jan 2011 16:19:36 -0600 Subject: [PATCH 1/3] invoke onDocPublished/onDocUnPublished on doc save and doc edit --- manager/processors/save_content.processor.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/manager/processors/save_content.processor.php b/manager/processors/save_content.processor.php index f4c81e1abc..b269370478 100755 --- a/manager/processors/save_content.processor.php +++ b/manager/processors/save_content.processor.php @@ -312,6 +312,11 @@ exit; } + //Invoke onDocPublished (onDocUnPublished could never be called here) + if($published == 1) { + $modx->invokeEvent("OnDocPublished",array("docid"=>$key)); + } + $tvChanges = array(); foreach ($tmplvars as $field => $value) { if (is_array($value)) { @@ -488,6 +493,13 @@ echo "An error occured while attempting to save the edited document. The generated SQL is: $sql ."; } + // Invoke onDocPublished/onDocUnPublished + if($was_published == 1 AND $published == 0) { + $modx->invokeEvent("OnDocUnPublished",array("docid"=>$id)); + } elseif ($was_published == 0 AND $published == 1) { + $modx->invokeEvent("OnDocPublished",array("docid"=>$id)); + } + // update template variables $rs = $modx->db->select('id, tmplvarid', $tbl_site_tmplvar_contentvalues, 'contentid='. $id); $tvIds = array (); From 6053f85c59f95c5632669042e193a09925ef5025 Mon Sep 17 00:00:00 2001 From: Charlie Madison Date: Tue, 25 Jan 2011 16:24:10 -0600 Subject: [PATCH 2/3] invoke onDocPublished/onDocUnPublished on timed published/unpublished documents --- .../includes/document.parser.class.inc.php | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/manager/includes/document.parser.class.inc.php b/manager/includes/document.parser.class.inc.php index 494070fd89..ecebdf55ad 100755 --- a/manager/includes/document.parser.class.inc.php +++ b/manager/includes/document.parser.class.inc.php @@ -568,16 +568,41 @@ function checkPublishStatus() { @include $this->config["base_path"] . "assets/cache/sitePublishing.idx.php"; $timeNow= time() + $this->config['server_offset_time']; if ($cacheRefreshTime <= $timeNow && $cacheRefreshTime != 0) { - // now, check for documents that need publishing - $sql = "UPDATE ".$this->getFullTableName("site_content")." SET published=1, publishedon=".time()." WHERE ".$this->getFullTableName("site_content").".pub_date <= $timeNow AND ".$this->getFullTableName("site_content").".pub_date!=0 AND published=0"; - if (@ !$result= $this->db->query($sql)) { - $this->messageQuit("Execution of a query to the database failed", $sql); + // Get documents that need to be published or unpublished + $sql = array(); + $sql[] = "SELECT id"; + $sql[] = "FROM {$this->getFullTableName('site_content')}"; + $sql[] = "WHERE "; + $sql[] = "(pub_date <= {$timeNow} AND pub_date != 0 AND published = 0) "; // $unpublished == ""; + $sql[] = " OR "; + $sql[] = " (unpub_date <= $timeNow AND unpub_date != 0 AND published = 1)"; // $published == ""; + $sql = implode(' ', $sql); + + $results = $this->db->makeArray($this->db->query($sql)); + $to_publish = array(); + $to_unpublish = array(); + foreach($results as $result) { + if($result['published'] != 1) { + $to_publish[] = $result['id']; + } else { + $to_unpublish[] = $result['id']; + } + } + + if( is_array($to_publish) and !empty($to_publish)) { + $publish_query = "UPDATE ".$this->getFullTableName("site_content")." SET published=1, publishedon=".time()." WHERE id IN (".implode(',', $to_publish).")"; + $this->db->query($publish_query); + foreach($to_publish as $doc) { + $this->invokeEvent("OnDocPublished",array("docid"=>$doc['id'])); + } } - // now, check for documents that need un-publishing - $sql= "UPDATE " . $this->getFullTableName("site_content") . " SET published=0, publishedon=0 WHERE " . $this->getFullTableName("site_content") . ".unpub_date <= $timeNow AND " . $this->getFullTableName("site_content") . ".unpub_date!=0 AND published=1"; - if (@ !$result= $this->db->query($sql)) { - $this->messageQuit("Execution of a query to the database failed", $sql); + if( is_array($to_unpublish) and !empty($to_unpublish)) { + $unpublish_query = "UPDATE ".$this->getFullTableName("site_content")." SET published=0, publishedon=0 WHERE id IN (".implode(',', $to_unpublish).")"; + $this->db->query($unpublish_query); + foreach($to_unpublish as $doc) { + $this->invokeEvent("OnDocUnPublished",array("docid"=>$doc['id'])); + } } // clear the cache @@ -597,6 +622,7 @@ function checkPublishStatus() { closedir($handle); } + // (TODO: Merge the 2 queries below to offset the added query above) // update publish time file $timesArr= array (); $sql= "SELECT MIN(pub_date) AS minpub FROM " . $this->getFullTableName("site_content") . " WHERE pub_date>$timeNow"; From 5105915186606ddce99837e9453b914703dbb5fc Mon Sep 17 00:00:00 2001 From: Charlie Madison Date: Wed, 26 Jan 2011 17:51:42 -0600 Subject: [PATCH 3/3] corrected $doc when events were invoked --- manager/includes/document.parser.class.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manager/includes/document.parser.class.inc.php b/manager/includes/document.parser.class.inc.php index ecebdf55ad..08689f9fb8 100755 --- a/manager/includes/document.parser.class.inc.php +++ b/manager/includes/document.parser.class.inc.php @@ -593,7 +593,7 @@ function checkPublishStatus() { $publish_query = "UPDATE ".$this->getFullTableName("site_content")." SET published=1, publishedon=".time()." WHERE id IN (".implode(',', $to_publish).")"; $this->db->query($publish_query); foreach($to_publish as $doc) { - $this->invokeEvent("OnDocPublished",array("docid"=>$doc['id'])); + $this->invokeEvent("OnDocPublished",array("docid"=>$doc)); } } @@ -601,7 +601,7 @@ function checkPublishStatus() { $unpublish_query = "UPDATE ".$this->getFullTableName("site_content")." SET published=0, publishedon=0 WHERE id IN (".implode(',', $to_unpublish).")"; $this->db->query($unpublish_query); foreach($to_unpublish as $doc) { - $this->invokeEvent("OnDocUnPublished",array("docid"=>$doc['id'])); + $this->invokeEvent("OnDocUnPublished",array("docid"=>$doc)); } }