Skip to content
This repository was archived by the owner on Mar 8, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions manager/includes/document.parser.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

// 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));
}
}

// clear the cache
Expand All @@ -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";
Expand Down
12 changes: 12 additions & 0 deletions manager/processors/save_content.processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -488,6 +493,13 @@
echo "An error occured while attempting to save the edited document. The generated SQL is: <i> $sql </i>.";
}

// 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 ();
Expand Down