From 1637680850c3dc367f633844e095a274122e6d83 Mon Sep 17 00:00:00 2001 From: Matt McNaney Date: Tue, 29 Jan 2019 10:10:27 -0500 Subject: [PATCH] Fixed bugs with publish date. --- Module.php | 19 +++--------------- boost/boost.php | 2 +- boost/dependency.xml | 2 +- boost/update.php | 8 ++++++++ class/Factory/EntryFactory.php | 7 +++++++ class/Factory/PublishFactory.php | 31 ++++++++++++++++++++++++++---- javascript/EntryList/EntryList.jsx | 7 +++---- npm-shrinkwrap.json | 2 +- package.json | 2 +- 9 files changed, 52 insertions(+), 28 deletions(-) diff --git a/Module.php b/Module.php index 3ebfce1..e47f889 100644 --- a/Module.php +++ b/Module.php @@ -16,8 +16,6 @@ use Canopy\Response; use Canopy\Server; -require_once PHPWS_SOURCE_DIR . 'src/Module.php'; - class Module extends \Canopy\Module implements \Canopy\SettingDefaults { @@ -29,18 +27,6 @@ public function __construct() $this->setProperName('Stories'); spl_autoload_register('\stories\Module::autoloader', true, true); } - - public function needsUpdate() { - if (empty($this->file_version)) { - $this->loadFileVersion(); - } - return version_compare($this->file_version, $this->version, '>'); - } - - public function loadFileVersion() { - include PHPWS_SOURCE_DIR . 'mod/' . $this->title . '/boost/boost.php'; - $this->file_version = $version; - } public function getSettingDefaults() { @@ -110,11 +96,12 @@ public function runTime(Request $request) private function frontPage(Request $request) { - if (!$request->isGet() || $request->getUrl() != '/') { + if (!empty($request->getModule())) { return; } if ($this->needsUpdate()) { - \Layout::add('
Stories needs updating.
', 'stories', 'stories', true); + \Layout::add('
Stories needs updating.
', + 'stories', 'stories', true); return; } $featureView = new \stories\View\FeatureView; diff --git a/boost/boost.php b/boost/boost.php index 947b14c..26ef7f8 100644 --- a/boost/boost.php +++ b/boost/boost.php @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ $proper_name = 'Stories'; -$version = '1.6.0'; +$version = '1.6.1'; $register = false; $unregister = false; $import_sql = false; diff --git a/boost/dependency.xml b/boost/dependency.xml index 245f858..2924f22 100644 --- a/boost/dependency.xml +++ b/boost/dependency.xml @@ -3,7 +3,7 @@ core Canopy Core - 3.0.4 + 3.0.5 http://github.com/AppStateESS/canopy/ \ No newline at end of file diff --git a/boost/update.php b/boost/update.php index 2c0b4b0..cafb385 100644 --- a/boost/update.php +++ b/boost/update.php @@ -102,6 +102,8 @@ public function run() $this->update('1.5.8'); case $this->compare('1.6.0'): $this->update('1.6.0'); + case $this->compare('1.6.1'): + $this->update('1.6.1'); } return $this->content; } @@ -343,6 +345,12 @@ private function v1_6_0() $changes[] = 'Fixed permanent link.'; $this->addContent('1.6.0', $changes); } + + private function v1_6_1() + { + $changes[] = 'Fixed bugs with publish date.'; + $this->addContent('1.6.1', $changes); + } private function addContent($version, array $changes) { diff --git a/class/Factory/EntryFactory.php b/class/Factory/EntryFactory.php index d85854c..ec57dd7 100644 --- a/class/Factory/EntryFactory.php +++ b/class/Factory/EntryFactory.php @@ -614,6 +614,13 @@ private function patchEntry(Resource $entry, $param, $value) $publishFactory->publishEntry($entry->id, $entry->publishDate); } + $entry->published = $value; + break; + + case 'publishDate': + $publishFactory->updatePublishDateByEntryId($entry->id, $value); + $entry->publishDate = $value; + break; default: $entry->$param = $value; diff --git a/class/Factory/PublishFactory.php b/class/Factory/PublishFactory.php index cfaf502..1a94fb8 100644 --- a/class/Factory/PublishFactory.php +++ b/class/Factory/PublishFactory.php @@ -61,7 +61,29 @@ public function publishEntry(int $entryId, int $publishDate) } } - public function publishShare(int $shareId, int $publishDate, int $showInList=1) + /** + * Changes the publish date of an entry only. Unpublished entries are + * ignored. + * @param int $entryId + * @param type $publishDate + * @return type + */ + public function updatePublishDateByEntryId(int $entryId, $publishDate) + { + $publishId = $this->getPublishIdByEntryId($entryId); + if (empty($publishId)) { + return; + } + $db = Database::getDB(); + $tbl = $db->addTable('storiespublish'); + $tbl->addValue('entryId', $entryId); + $tbl->addValue('publishDate', $publishDate); + $tbl->addFieldConditional('entryId', $entryId); + $db->update(); + } + + public function publishShare(int $shareId, int $publishDate, + int $showInList = 1) { $db = Database::getDB(); $tbl = $db->addTable('storiespublish'); @@ -162,7 +184,7 @@ private function deleteTrackHosts(int $entryId) $tbl->addFieldConditional('entryId', $entryId); return $db->delete(); } - + public function patchByEntry($entryId, $varname, $value) { $publish = $this->loadByEntryId($entryId); @@ -170,7 +192,7 @@ public function patchByEntry($entryId, $varname, $value) $this->saveResource($publish); return true; } - + public function patchByShare($shareId, $varname, $value) { $publish = $this->loadByShareId($shareId); @@ -193,6 +215,7 @@ public function listing(array $options = null) $tbl = $db->addTable('storiespublish'); $tbl->addOrderBy('publishDate', 'desc'); $tbl->addFieldConditional('showInList', 1); + $tbl->addFieldConditional('publishDate', time(), '<='); /** * To get an accurate test to see if there are more entries for @@ -298,7 +321,7 @@ public function loadByShareId($shareId) $publish = $this->build($row); return $publish; } - + public function loadByEntryId($entryId) { $db = Database::getDB(); diff --git a/javascript/EntryList/EntryList.jsx b/javascript/EntryList/EntryList.jsx index ff5b0b9..c713067 100644 --- a/javascript/EntryList/EntryList.jsx +++ b/javascript/EntryList/EntryList.jsx @@ -194,10 +194,9 @@ export default class EntryList extends Component { }, this.load) } - setPublishDate(e) { - let entry = this.currentEntry() - const value = e.target.value - entry.publishDate = moment(value).unix() + setPublishDate(publishDate) { + const entry = this.currentEntry() + entry.publishDate = publishDate.getTime() / 1000 this.updateEntry(entry) } diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 421ec59..432b583 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "stories", - "version": "1.6.0", + "version": "1.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a451e5a..35e26ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stories", - "version": "1.6.0", + "version": "1.6.1", "description": "Canopy blog module", "repository": { "type": "git",