-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #607 from takeit/console_commands
[CS-5270] - Merge cron jobs tasks to console commands
- Loading branch information
Showing
49 changed files
with
1,261 additions
and
836 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file modified
0
newscoop/application/modules/admin/controllers/SubscriptionController.php
100644 → 100755
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,245 +1,3 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
global $CAMPSITE_DIR; | ||
|
||
require_once __DIR__ . '/../application.php'; | ||
|
||
$application->bootstrap(); | ||
$GLOBALS['g_campsiteDir'] = $CAMPSITE_DIR = realpath(dirname(dirname(__FILE__))); | ||
|
||
if (!defined('WWW_DIR')) { | ||
define('WWW_DIR', $GLOBALS['g_campsiteDir']); | ||
} | ||
|
||
require_once __DIR__ . '/cli_script_lib.php'; | ||
|
||
$ETC_DIR = __DIR__ . '/../conf'; | ||
|
||
if (!camp_is_readable("$ETC_DIR/install_conf.php")) { | ||
exit; | ||
} | ||
|
||
// includes installation configuration file | ||
require_once("$ETC_DIR/install_conf.php"); | ||
|
||
if (!is_file("$ETC_DIR/database_conf.php")) { | ||
echo "\n"; | ||
echo "Database configuration file is missed!\n"; | ||
echo "\n"; | ||
exit; | ||
} | ||
|
||
// includes campsite initialisation | ||
require_once("$CAMPSITE_DIR/include/campsite_init.php"); | ||
|
||
// defines the notifier template file name | ||
define('NOTIFIER_TEMPLATE', '_events_notifier.tpl'); | ||
|
||
// connects to database server | ||
if (db_server_connect() == false) { | ||
msg_error('Connecting to DB server'); | ||
exit; | ||
} | ||
|
||
// sets the array which holds message data | ||
$message = array(); | ||
|
||
// reads reply address | ||
$message['reply'] = get_reply_address(); | ||
|
||
// reads events | ||
$tstamp = get_event_timestamp(); | ||
|
||
$sql_query = "SELECT u.Name AS UserRealName, u.EMail AS UserEMail, " | ||
. "u.UName AS UserName, e.Name AS EventName, l.text AS LogText, " | ||
. "l.time_created AS LogTimeCreated, NOW() AS RightNow " | ||
. "FROM Log AS l, liveuser_users AS u, Events AS e " | ||
. "WHERE l.fk_event_id = e.Id AND e.Notify = 'Y' AND l.fk_user_id = u.Id " | ||
. "AND l.time_created > '" . $tstamp . "' " | ||
. "ORDER BY l.time_created ASC"; | ||
if (!$result = mysql_query($sql_query)) { | ||
msg_error('Reading log timestamp'); | ||
exit; | ||
} | ||
|
||
$i = 0; | ||
$num_rows = mysql_num_rows($result); | ||
|
||
// if events log exists, inits smarty template system | ||
if ($num_rows > 0) { | ||
$tpl = init_smarty(); | ||
$recipients = get_users_to_notify(); | ||
} | ||
|
||
$last_tstamp = 0; | ||
while ($i < $num_rows && $row = mysql_fetch_array($result, MYSQL_ASSOC)) { | ||
$last_tstamp = $row['LogTimeCreated']; | ||
|
||
// assigns values to smarty template variables | ||
$tpl->assign('user_real_name', $row['UserRealName']); | ||
$tpl->assign('user_name', $row['UserName']); | ||
$tpl->assign('user_email', $row['UserEMail']); | ||
$tpl->assign('event_text', $row['LogText']); | ||
$tpl->assign('event_timestamp', $row['LogTimeCreated']); | ||
|
||
// sets the message body text | ||
$message['text'] = ''; | ||
$message['text'] = $tpl->fetch(NOTIFIER_TEMPLATE); | ||
|
||
// reads users emails to notify to | ||
if (sizeof($recipients) <= 0) { | ||
continue; | ||
} | ||
|
||
// sets message recipients and subject | ||
$message['recipients'] = $recipients; | ||
$message['subject'] = $row['EventName']; | ||
|
||
// sends email message | ||
send_email($message); | ||
$i++; | ||
} | ||
|
||
if ($last_tstamp != 0) { | ||
$sql_query = "UPDATE AutoId SET LogTStamp = '" . $last_tstamp . "'"; | ||
mysql_query($sql_query); | ||
} | ||
|
||
|
||
/** | ||
* Reads reply address | ||
* | ||
* @return string | ||
*/ | ||
function get_reply_address() | ||
{ | ||
$sql_query = "SELECT EMail FROM liveuser_users WHERE UName = 'admin'"; | ||
if (!$result = mysql_query($sql_query)) { | ||
return; | ||
} | ||
|
||
if (mysql_num_rows($result) <= 0) { | ||
return; | ||
} | ||
|
||
$row = mysql_fetch_array($result, MYSQL_ASSOC); | ||
mysql_free_result($result); | ||
|
||
return $row['EMail']; | ||
} // fn get_reply_address | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
function get_event_timestamp() | ||
{ | ||
$sql_query = 'SELECT LogTStamp FROM AutoId'; | ||
if (!$result = mysql_query($sql_query)) { | ||
msg_error('Getting logtstamp'); | ||
exit; | ||
} | ||
|
||
if (mysql_num_rows($result) <= 0) { | ||
msg_error('There is no logtstamp'); | ||
exit; | ||
} | ||
|
||
$row = mysql_fetch_array($result, MYSQL_ASSOC); | ||
mysql_free_result($result); | ||
|
||
return $row['LogTStamp']; | ||
} // fn get_event | ||
|
||
|
||
/** | ||
* Get user emails to notify | ||
* | ||
* @return array $users | ||
* An array with users emails to notify to | ||
*/ | ||
function get_users_to_notify() | ||
{ | ||
global $application; | ||
$container = $application->getBootstrap()->getResource('container'); | ||
return $container->getService('notification')->findRecipients(); | ||
} | ||
|
||
/** | ||
* @return boolean | ||
* true on success, false on failure | ||
*/ | ||
function send_email($p_message) | ||
{ | ||
if (!is_array($p_message) || empty($p_message)) { | ||
return false; | ||
} | ||
|
||
$mail = new Zend_Mail('utf-8'); | ||
$mail->addTo($p_message['recipients']); | ||
$mail->setSubject($p_message['subject']); | ||
$mail->setBodyText($p_message['text']); | ||
|
||
if (!empty($p_message['reply'])) { | ||
$mail->setReplyTo($p_message['reply']); | ||
} | ||
|
||
return $mail->send(); | ||
} // fn send_email | ||
|
||
|
||
/** | ||
* @return object $tpl | ||
* Smarty object | ||
*/ | ||
function init_smarty() | ||
{ | ||
global $CAMPSITE_DIR; | ||
|
||
// instantiates smarty template system | ||
$tpl = new Smarty(); | ||
|
||
// inits smarty configuration settings | ||
$tpl->left_delimiter = '{{'; | ||
$tpl->right_delimiter = '}}'; | ||
$tpl->force_compile = true; | ||
$tpl->config_dir = $CAMPSITE_DIR.'/include/smarty/configs'; | ||
$tpl->template_dir = $CAMPSITE_DIR.'/themes/system_templates'; | ||
$tpl->compile_dir = $CAMPSITE_DIR.'/cache'; | ||
$tpl->auto_literal = false; | ||
|
||
return $tpl; | ||
} // fn init_smarty | ||
|
||
|
||
/** | ||
* @return boolean | ||
*/ | ||
function db_server_connect() | ||
{ | ||
global $Campsite; | ||
|
||
$db_host = $Campsite['DATABASE_SERVER_ADDRESS'] | ||
.':'.$Campsite['DATABASE_SERVER_PORT']; | ||
$db_user = $Campsite['DATABASE_USER']; | ||
$db_pass = $Campsite['DATABASE_PASSWORD']; | ||
$db_name = $Campsite['DATABASE_NAME']; | ||
$link = mysql_connect($db_host, $db_user, $db_pass); | ||
if (!$link) { | ||
return false; | ||
} | ||
|
||
mysql_select_db($db_name, $link); | ||
return mysql_query("SET NAMES 'utf8'"); | ||
} // fn db_server_connect | ||
|
||
|
||
/** | ||
* @param string $p_msg | ||
*/ | ||
function msg_error($p_msg) | ||
{ | ||
print('ERROR: ' . $p_msg); | ||
} // fn msg_error | ||
|
||
system(__DIR__ . '/../application/console newscoop:notifier:events'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,3 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
require_once dirname(__FILE__) . '/newscoop_bootstrap.php'; | ||
|
||
require_once WWW_DIR . '/include/campsite_init.php'; | ||
require_once WWW_DIR . '/classes/ArticlePublish.php'; | ||
require_once WWW_DIR . '/classes/IssuePublish.php'; | ||
|
||
// fill in HTTP_HOST to avoid notices in campsite_constants.php | ||
$_SERVER['HTTP_HOST'] = ''; | ||
$issueActions = IssuePublish::DoPendingActions(); | ||
$articleActions = ArticlePublish::DoPendingActions(); | ||
|
||
if ($issueActions > 0 || $articleActions > 0) { | ||
fopen(WWW_DIR.'/reset_cache', 'w'); | ||
} | ||
system(__DIR__ . '/../application/console newscoop:autopublish'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.