Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-16-2012, 11:35 AM
Altari Altari is offline
 
Join Date: Sep 2011
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default My cron doesn't work as expected (should post)

Hello,

(Sorry for my bad english)

I did a cron to post in each thread which didn't have any activity since 1 month, and send a mail to the author.
When i manually execute this cron, it work quite good : posts are posted, mails are sent etc.
But when the cron automatically execute, all the script is done without problems except the posts : No posts are posted, mails are sent, and no errors.

Another problem, is when i manually execute the cron posts are posted since my account, and not from the account id 1 like i wish.

Here is the portion of code which shoud post :
PHP Code:
$post = array();  
            
$postinfo = array();  
            
$errors = array();  

            
$userid 1
            
$forumid $donnees['forumid']; 

            
$foruminfo fetch_foruminfo($forumid);   
            
$bbuserinfo fetch_userinfo($userid);   
             
            
$post['message'] =  
                
'[B][COLOR=#008000]=================== 
                Ceci est un message automatique 
                =================== 

                Blablabla[/COLOR][/B]'
;   
                 
            
$post['userid'] = 1
            
$post['username'] = 'WEBSITE'
            
$post['title'] = 'Plus de nouvelles depuis 1 mois'
             
             
            
$post['poststarttime'] = TIMENOW;   
            
$post['posthash'] = md5($post['poststarttime'] . $bbuserinfo['userid'] . $bbuserinfo['salt']);  

            
$threadinfo fetch_threadinfo($donnees['threadid']); 
            
$postinfo = array(); 
            
$postinfo['visible'] = 1
            
$postinfo['specifiedpost'] = false
            
$postinfo['postid'] = 0

             
            
build_new_post('reply'$foruminfo$threadinfo$postinfo$post$errors); 
Here is all the cron :

PHP Code:
<?php
error_reporting
(E_ALL);
ini_set('display_errors''On');

set_time_limit(0);
if (!
is_object($vbulletin->db))
{
    exit;
}

require_once(
'./global.php');
require_once(
'includes/functions_newpost.php'); 
$deux_mois date("Y-m-d"mktime(0,0,0,date("m"),date("d")-60,date("Y")));
function 
unix_timestamp($date)
{
    
$date str_replace(array(' '':'), '-'$date);
    
$c    explode('-'$date);
    
$c    array_pad($c60);
    
array_walk($c'intval');
 
    return 
mktime($c[3], $c[4], $c[5], $c[1], $c[2], $c[0]);
}
$deux_mois unix_timestamp($deux_mois);

try
    {
    
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
    
$bdd = new PDO('mysql:host=localhost;dbname=XXX''root''XXXXXX'$pdo_options);
    
$req $bdd->query('SELECT threadid, postuserid, forumid, lastpost, lastposter FROM vb_thread WHERE lastpost < (UNIX_TIMESTAMP() - (30*24*3600)) AND visible = 1 AND open = 1 AND (forumid = 17 OR forumid = 30 OR forumid = 42)');
    while (
$donnees $req->fetch()){
        if(
$donnees['lastpost'] < $deux_mois OR $donnees['lastposter'] == 'WEBSITE'){
            
$changement $bdd->prepare("UPDATE vb_thread SET forumid = '179' WHERE threadid = :id");
            
$changement->execute(array('id' => $donnees['threadid']));
            
$changement->closeCursor();
            
            
$membre $bdd->prepare('SELECT userid, username, email FROM vb_user WHERE userid = :memberid');
            
$membre->execute(array('memberid' => $donnees['postuserid']));
            
$final_membre $membre->fetch();
            
$membre->closeCursor();
            
            if(!
preg_match("#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#"$final_membre['email'])){
                
$passage_ligne "\r\n";
            }
            else{
                
$passage_ligne "\n";
            }
            
            
$sujet 'Votre annonce a ?t? archiv?e automatiquement';
            
$contenu_mail_txt 'Bonjour '.$final_membre['username'].','.$passage_ligne.'Nous vous informons que l\'annonce dont vous trouverez le lien ci-dessous a ?t? automatiquement archiv?e en l\absence de nouvelles depuis deux mois.'.$passage_ligne.'Si cette annonce est toujours d\'actualit?, nous vous invitons ? faire un rapport aupr?s des mod?rateurs ou ? r?diger une nouvelle annonce.'.$passage_ligne;
            
$contenu_mail_txt .= $passage_ligne.'Lien de votre annonce : http://www.website.com/'.$donnees['threadid'].$passage_ligne;
            
$contenu_mail_txt .= $passage_ligne.'Cordialement,'.$passage_ligne.'L\'?quipe Website';
            
            echo 
'Mail envoy? ? '.$final_membre['username'].' avec succ?s ('.$final_membre['email'].')<br />';
            
vbmail($final_membre['email'], $sujet$contenu_mail_txt);
            
        }
        else{
            
$post = array(); 
            
$postinfo = array(); 
            
$errors = array(); 

            
$userid 1;
            
$forumid $donnees['forumid'];

            
$foruminfo fetch_foruminfo($forumid);  
            
$bbuserinfo fetch_userinfo($userid);  
            
            
$post['message'] = 
                
'[B][COLOR=#008000]===================
                Ceci est un message automatique
                ===================

                Bonjour,

                Merci de nous donner des nouvelles concernant cette annonce,
                Est elle toujours d\'actualit? ? 
                Nous vous invitons ? faire un rapport de mod?ration si elle n\'est plus d\'actualit?, ou ? simplement r?pondre ? ce message le cas ?ch?ant.
                Cordialement,
                L\'?quipe Website[/COLOR][/B]'
;  
                
            
$post['userid'] = 1;
            
$post['username'] = 'Website';
            
$post['title'] = 'Plus de nouvelles depuis 1 mois';
            
            
            
$post['poststarttime'] = TIMENOW;  
            
$post['posthash'] = md5($post['poststarttime'] . $bbuserinfo['userid'] . $bbuserinfo['salt']); 

            
$threadinfo fetch_threadinfo($donnees['threadid']);
            
$postinfo = array();
            
$postinfo['visible'] = 1;
            
$postinfo['specifiedpost'] = false;
            
$postinfo['postid'] = 0;

            
            
build_new_post('reply'$foruminfo$threadinfo$postinfo$post$errors);
        
            
$membre $bdd->prepare('SELECT userid, username, email FROM vb_user WHERE userid = :memberid');
            
$membre->execute(array('memberid' => $donnees['postuserid']));
            
$final_membre $membre->fetch();
            
$membre->closeCursor();
            
            if(!
preg_match("#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#"$final_membre['email'])){
                
$passage_ligne "\r\n";
            }
            else{
                
$passage_ligne "\n";
            }
            
            
$sujet 'Demande de nouvelles pour votre annonce';
            
$contenu_mail_txt 'Bonjour '.$final_membre['username'].','.$passage_ligne.'Voil? un mois que vous avez post? une annonce d\'adoption, sans qu\'il n\'y ait de nouvelles depuis. Afin de pr?server la qualit? des annonces sur Websiteet leur pertinence, merci de passer poster un message sur l\'annonce, ne serait ce que pour signaler qu\'elle est toujours d\'actualit?'.$passage_ligne.'Si cette annonce est obsol?te, nous vous invitons ? faire un rapport aux mod?rateurs ou ? le signaler dans le message afin qu\'elle soit archiv?e. Sans nouvelles de votre part ou d\'un autre membre, cette annonce sera automatiquement archiv?e dans 1 mois.';
            
$contenu_mail_txt .= $passage_ligne.'Lien de votre annonce : http://www.rescue-forum.com/discussions/'.$donnees['threadid'].$passage_ligne;
            
$contenu_mail_txt .= $passage_ligne.'Merci de votre compr?hension,'.$passage_ligne.'L\'?quipe RESCUE';
            
            echo 
'Mail envoy? ? '.$final_membre['username'].' avec succ?s ('.$final_membre['email'].')<br />';
            
vbmail($final_membre['email'], $sujet$contenu_mail_txt);
            
        }
    
    }
    
$req->closeCursor();
    }
    catch(
Exception $e){
        die(
'Erreur : '.$e->getMessage());
    }

?>
Thank you a lot
Reply With Quote
  #2  
Old 04-16-2012, 11:50 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The function build_new_post() uses some info from $vbulletin->userinfo, which will be whatever random user happens to run the cron job. Specifically, the from userid is taken from there even if you've set it already. So you either need to figure out a way around that, or else (re)write your own version.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:39 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03390 seconds
  • Memory Usage 2,257KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete