diff --git a/plugins/generic/scielo/SciELOPlugin.inc.php b/plugins/generic/scielo/SciELOPlugin.inc.php new file mode 100644 index 00000000000..e6aeba79a92 --- /dev/null +++ b/plugins/generic/scielo/SciELOPlugin.inc.php @@ -0,0 +1,60 @@ +getPluginPath() . '/settings.xml'; + } +} + +?> diff --git a/plugins/generic/scielo/SciELOStatsSender.inc.php b/plugins/generic/scielo/SciELOStatsSender.inc.php new file mode 100644 index 00000000000..d1cc6d19ec0 --- /dev/null +++ b/plugins/generic/scielo/SciELOStatsSender.inc.php @@ -0,0 +1,166 @@ +getBySetting($unregisteredSettingName, true); + + // Send journal stats. + while ($journal = $journalFactory->next()) { + if (!$this->_claimObject($journalSettingsDao, $journalId)) continue; + $lastStatsSendingDate = $journalSettingsDao->getSetting($journalId, 'scieloLastStatsSendingDate'); + + if (!$this->_isMigratedStatsSent($journalSettingsDao, $journalId)) { + $this->_sendMigratedStats($journalSettingsDao, ASSOC_TYPE_JOURNAL, $journal, $lastStatsSendingDate); + } + + $metrics = $journal->getMetrics(OJS_METRIC_TYPE_COUNTER); + } + + + $serverUrl = '200.136.72.14:8860/'; + $jsonMessage = json_encode(array( + 'code' => '123456', + 'journal' => '0034-8910', + 'issue' => '0034-891020090004', + 'article.y2011.m10.d01' => 100, + 'article.y2011.m10.d02' => 100, + 'article.y2011.m10.d03' => 100, + 'article.y2012.m11.d01' => 10, + 'article.y2012.m11.a02' => 10, + 'article.y2012.m11.a03' => 10, + 'article.y2012.m10.total' => 300, + 'article.y2012.m11.total' => 30, + 'article.y2012.total' => 330, + 'total' => 330, + 'bra' => 200, + 'mex' => 100, + 'arg' => 10, + 'col' => 20 + )); + + $serverUrl = $serverUrl . 'api/v1/article/bulk?data=' . $jsonMessage ; + $webServiceRequest = new WebServiceRequest($serverUrl); + $webServiceRequest->setMethod('POST'); + $webServiceRequest->setAccept('application/json'); + $webServiceRequest->setHeader('Content-Type', 'application/json'); + + $webService = new WebService(); + $webService->call($webServiceRequest); + + // Check the reponse status. + if ($webService->getLastResponseStatus() == '200') { + return true; + } else { + return false; + } + } + + + // + // Private helper methdos. + // + /** + * Tries to claim the passed object id to start the statistics + * send process. + * @param $settingsDao SettingsDAO + * @param $objectId int + * @return boolean Whether or not the claim was successful. + */ + private function _claimObject($settingsDao, $objectId) { + if (!is_a($settingsDao, 'SettingsDAO')) assert(false); + + $claimedSettingName = 'scieloObjectClaimed'; + if (!$settingsDao->getSetting($objectId, $claimedSettingName)) { + // Claim the object. + $settingsDao->updateSetting($objectId, $claimedSettingName, true); + return true; + } else { + // Already claimed by another instance of this script. + return false; + } + } + + /** + * Check if the statistics collected by previous versions of + * OJS and migrated when upgrading were already sent to SciELO. + * @param $settingsDao SettingsDAO + * @param $objectId int + * @return boolean + */ + private function _isMigratedStatsSent($settingsDao, $objectId) { + if (!is_a($settingsDao, 'SettingsDAO')) assert(false); + return $settingsDao->getSetting($objectId, 'scieloMigratedStatsSent'); + } + + /** + * Send the statistics collected by previous versions of OJS + * and migrated when upgrading to SciELO. + * @param $settingsDao SettingsDAO + * @param $assocType int + * @param $assocObject DataObject + * @param $lastStatsSendingDate timestamp + */ + private function _sendMigratedStats($settingsDao, $assocType, $assocObject, $lastStatsSendingDate) { + if (!is_a($settingsDao, 'SettingsDAO')) assert(false); + switch ($assocType) { + case ASSOC_TYPE_JOURNAL: + // Get the statistics. + $metrics = $assocObject->getMetrics(OJS_METRIC_TYPE_LEGACY_COUNTER, array(STATISTICS_DIMENSION_MONTH)); + if($metrics) { + $message = array( + 'code' => $assocObject->getId(), + 'journal.y2011.m10.d01' => 100, + 'article.y2011.m10.d02' => 100, + 'article.y2011.m10.d03' => 100, + 'article.y2012.m11.d01' => 10, + 'article.y2012.m11.a02' => 10, + 'article.y2012.m11.a03' => 10, + 'article.y2012.m10.total' => 300, + 'article.y2012.m11.total' => 30, + 'article.y2012.total' => 330, + 'total' => 330, + 'bra' => 200, + 'mex' => 100, + 'arg' => 10, + 'col' => 20 + ); + } + } + } +} +?> \ No newline at end of file diff --git a/plugins/generic/scielo/index.php b/plugins/generic/scielo/index.php new file mode 100644 index 00000000000..6068a76cbd4 --- /dev/null +++ b/plugins/generic/scielo/index.php @@ -0,0 +1,21 @@ + diff --git a/plugins/generic/scielo/locale/en_US/locale.xml b/plugins/generic/scielo/locale/en_US/locale.xml new file mode 100644 index 00000000000..2d0eacb5159 --- /dev/null +++ b/plugins/generic/scielo/locale/en_US/locale.xml @@ -0,0 +1,16 @@ + + + + + + + SciELO statistics + Communicate with SciELO server to post and get data objects usage statistics. + diff --git a/plugins/generic/scielo/scheduledTasks.xml b/plugins/generic/scielo/scheduledTasks.xml new file mode 100644 index 00000000000..a2aa2a65a78 --- /dev/null +++ b/plugins/generic/scielo/scheduledTasks.xml @@ -0,0 +1,25 @@ + + + + + + + + + Send usage statistics data to SciELO database. + + diff --git a/plugins/generic/scielo/settings.xml b/plugins/generic/scielo/settings.xml new file mode 100644 index 00000000000..25facafcc51 --- /dev/null +++ b/plugins/generic/scielo/settings.xml @@ -0,0 +1,24 @@ + + + + + + + + enabled + false + + + serverUrl + "http://200.136.72.14:8860/" + + +