Commit af9363c9 authored by theo lem's avatar theo lem
Browse files

Merge branch 'datetime_usage' into 'master'

Datetime usage

See merge request framasoft/framaforms!40
parents c4610d21 914868b1
......@@ -51,7 +51,8 @@ function framaforms_install () {
framaforms_set_variables_mail();
framaforms_set_variables_pages();
$now = date('Y/m/d/ h:m:s', time());
variable_set('framaforms_cron_last', strtotime($now)); // the last framforms cron run
variable_set('framaforms_cron_last', new DateTime()); // the last framforms cron run
variable_set('framaforms_cron_frequency', '1 hour');
variable_set('framaforms_expiration_period_default_value', 26); // default creation-expiration time interval
variable_set('framaforms_deletion_period_value', 9); // default expiration-deletion time interval
variable_set('framaforms_notification_period_value', 2); // default notification-expiration time interval
......@@ -83,12 +84,6 @@ function framaforms_install () {
if(!isset($page_settings)){
variable_set('pathauto_node_page_pattern', '[node:title]');
}
//TODO : set index on install
if( db_table_exists('locales_source') && !db_index_exists('locales_source', 'locales_source_source_context_textgroup_idx')) {
db_add_index('locales_source', 'locales_source_source_context_textgroup_idx',
array('source', 'context', 'textgroup'));
}
}
/**
......
......@@ -548,20 +548,21 @@ function framaforms_cron(){
module_load_include('inc', 'framaforms', 'includes/framaforms.expiration');
global $user;
/**
* Parameters for adjusting the expiration and deletion period,
* as well as the cron frequency.
* Parameter for adjusting cron frequency.
*/
$cron_last = date('Y/m/d/ h:m:s', variable_get('framaforms_cron_last')); // the last time the cron task was run.
$cron_limit = date('Y/m/d/ h:m:s', strtotime('-'. variable_get('framaforms_cron_limit')));
$now = date('Y/m/d/ h:m:s', time());
$framaforms_cron_last = variable_get('framaforms_cron_last'); // the last time the cron task was run.
$cron_limit = new DateTime();
$cron_limit->setTimestamp($framaforms_cron_last);
$cron_limit->modify('+'.variable_get('framaforms_cron_frequency'));
$now = new DateTime();
// if the cron was executed less than 24h ago, do nothing.
if(strtotime($cron_last) > strtotime($cron_limit)){
return;
if($now < $cron_limit){
return;
}
// else, proceed to cron.
watchdog('framaforms', "Running framaforms cron.");
variable_set('framaforms_cron_last', strtotime($now));
variable_set('framaforms_cron_last', $now->getTimestamp());
/**
* Handle expired nodes
......
......@@ -13,7 +13,7 @@
function make_forms_expire(){
$expiration_period = variable_get('framaforms_expiration_period_default_value');
// If the user set the expiration period to 0, don't make the nodes expire.
if($expiration_period == 0 || (!is_numeric($expiration_period)) ){
if($expiration_period == 0){
return;
}
$expiration_period .= ' weeks';
......@@ -87,8 +87,14 @@ function notify_user_of_expiration ($record) {
global $base_url; //use the global variable of Drupal for the site's URL
$expiration_period = variable_get('framaforms_notification_period_value') .' weeks';
$deletion_period = variable_get('framaforms_deletion_period_value') .' weeks';
$expiration_date = date("d/m/Y", strtotime('+'.$expiration_period));
$delete_date = date("d/m/Y", strtotime('+'.$deletion_period));
$expiration_date = new DateTime();
$expiration_date->modify("+".$expiration_period);
$delete_date = clone $expiration_date;
$delete_date->modify($deletion_period);
$delete_date = $delete_date->getTimestamp();
$expiration_date = $expiration_date->getTimestamp();
$node_url = $base_url . url('node/'.$record->nid);
$mail_body = variable_get('framaforms_mail_user_notification_body');
$mail_subject = variable_get('framaforms_mail_user_notification_subject');
......@@ -117,7 +123,7 @@ function notify_user_of_expiration ($record) {
*/
function update_modified_nodes () {
$expiration_period = variable_get('framaforms_notification_period_value');
if($expiration_period == 0 || (!is_numeric($expiration_period)) ){
if($expiration_period == 0){
return;
}
$expiration_period .= ' weeks';
......@@ -133,6 +139,7 @@ function update_modified_nodes () {
on node.nid=framaforms_expired.nid
where field_data_field_form1_expiration.field_form1_expiration_value
> to_timestamp(framaforms_expired.date_notified) + interval'%s'
and node.nid not in (select nid from framaforms_expired)
", $expiration_period));
$nid_changed= 0 ;
......@@ -163,7 +170,7 @@ function update_modified_nodes () {
function delete_expired_nodes () {
// if the user set the deletion period to 0, don't delete the forms
$deletion_period = variable_get('framaforms_deletion_period_value');
if($deletion_period == 0 || (!is_numeric($deletion_period)) ){
if($deletion_period == 0){
return;
}
$deletion_period .= ' weeks';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment