mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Merge branch 'dolibarr_partnership' of https://github.com/NextGestion/dolibarr into dolibarr_partnership
This commit is contained in:
commit
345fef99b6
|
|
@ -93,8 +93,8 @@ if ($action == 'setting') {
|
|||
$error += $partnership->delete_menus();
|
||||
$error += $partnership->insert_menus();
|
||||
|
||||
if(GETPOST("PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL",'int'))
|
||||
dolibarr_set_const($db, "PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL", GETPOST("PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL",'int'), 'chaine', 0, '', $conf->entity);
|
||||
if (GETPOST("PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL", 'int'))
|
||||
dolibarr_set_const($db, "PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL", GETPOST("PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL", 'int'), 'chaine', 0, '', $conf->entity);
|
||||
dolibarr_set_const($db, "PARTNERSHIP_BACKLINKS_TO_CHECK", GETPOST("PARTNERSHIP_BACKLINKS_TO_CHECK"), 'chaine', 0, '', $conf->entity);
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ print '<td><span class="opacitymedium">'.$langs->trans("partnershipforthirdparty
|
|||
print '</tr>';
|
||||
|
||||
|
||||
if($conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member'){
|
||||
if ($conf->global->PARTNERSHIP_IS_MANAGED_FOR == 'member') {
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL").'</td>';
|
||||
print '<td>';
|
||||
$dnbdays = '7';
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
|
|||
dol_include_once('partnership/lib/partnership.lib.php');
|
||||
dol_include_once('/partnership/class/partnership.class.php');
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
|
||||
require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
|
||||
/**
|
||||
* Class with cron tasks of Partnership module
|
||||
|
|
@ -53,7 +53,7 @@ class PartnershipUtils
|
|||
$this->db = $db;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action executed by scheduler to cancel status of partnership when subscription is expired + x days. (Max number of action batch per call = $conf->global->PARTNERSHIP_MAX_EXPIRATION_CANCEL_PER_CALL)
|
||||
*
|
||||
|
|
@ -65,163 +65,147 @@ class PartnershipUtils
|
|||
{
|
||||
global $conf, $langs, $user;
|
||||
|
||||
$managedfor = $conf->global->PARTNERSHIP_IS_MANAGED_FOR;
|
||||
$managedfor = $conf->global->PARTNERSHIP_IS_MANAGED_FOR;
|
||||
|
||||
if($managedfor != 'member'){
|
||||
if ($managedfor != 'member') {
|
||||
return 0; // If option 'PARTNERSHIP_IS_MANAGED_FOR' = 'thirdparty', this cron job does nothing.
|
||||
}
|
||||
|
||||
$partnership = new Partnership($this->db);
|
||||
$MAXPERCALL = (empty($conf->global->PARTNERSHIP_MAX_EXPIRATION_CANCEL_PER_CALL) ? 25 : $conf->global->PARTNERSHIP_MAX_EXPIRATION_CANCEL_PER_CALL); // Limit to 25 per call
|
||||
$partnership = new Partnership($this->db);
|
||||
$MAXPERCALL = (empty($conf->global->PARTNERSHIP_MAX_EXPIRATION_CANCEL_PER_CALL) ? 25 : $conf->global->PARTNERSHIP_MAX_EXPIRATION_CANCEL_PER_CALL); // Limit to 25 per call
|
||||
|
||||
$langs->loadLangs(array("partnership", "member"));
|
||||
$langs->loadLangs(array("partnership", "member"));
|
||||
|
||||
$error = 0;
|
||||
$erroremail = '';
|
||||
$this->output = '';
|
||||
$this->error = '';
|
||||
$partnershipsprocessed = array();
|
||||
$error = 0;
|
||||
$erroremail = '';
|
||||
$this->output = '';
|
||||
$this->error = '';
|
||||
$partnershipsprocessed = array();
|
||||
|
||||
$gracedelay=$conf->global->PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL;
|
||||
if ($gracedelay < 1)
|
||||
{
|
||||
$this->error='BadValueForDelayBeforeCancelCheckSetup';
|
||||
return -1;
|
||||
}
|
||||
$gracedelay=$conf->global->PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL;
|
||||
if ($gracedelay < 1) {
|
||||
$this->error='BadValueForDelayBeforeCancelCheckSetup';
|
||||
return -1;
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::doCancelStatusOfMemberPartnership cancel expired partnerships with grace delay of ".$gracedelay);
|
||||
dol_syslog(get_class($this)."::doCancelStatusOfMemberPartnership cancel expired partnerships with grace delay of ".$gracedelay);
|
||||
|
||||
$now = dol_now();
|
||||
$datetotest = dol_time_plus_duree($now, -1 * abs($gracedelay), 'd');
|
||||
$now = dol_now();
|
||||
$datetotest = dol_time_plus_duree($now, -1 * abs($gracedelay), 'd');
|
||||
|
||||
$this->db->begin();
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "SELECT p.rowid, p.fk_member, p.status";
|
||||
$sql .= ", d.datefin, d.fk_adherent_type, dty.subscription";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."partnership as p";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d on (d.rowid = p.fk_member)";
|
||||
$sql = "SELECT p.rowid, p.fk_member, p.status";
|
||||
$sql .= ", d.datefin, d.fk_adherent_type, dty.subscription";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."partnership as p";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d on (d.rowid = p.fk_member)";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_type as dty on (dty.rowid = d.fk_adherent_type)";
|
||||
$sql .= " WHERE fk_member > 0";
|
||||
$sql .= " AND (d.datefin < '".$this->db->idate($datetotest)."' AND dty.subscription = 1)";
|
||||
$sql .= " AND p.status = ".$partnership::STATUS_ACCEPTED; // Only accepted not yet canceled
|
||||
$sql .= $this->db->order('d.rowid','ASC');
|
||||
// Limit is managed into loop later
|
||||
$sql .= " AND p.status = ".$partnership::STATUS_ACCEPTED; // Only accepted not yet canceled
|
||||
$sql .= $this->db->order('d.rowid', 'ASC');
|
||||
// Limit is managed into loop later
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$numofexpiredmembers = $this->db->num_rows($resql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
$numofexpiredmembers = $this->db->num_rows($resql);
|
||||
|
||||
$somethingdoneonpartnership = 0;
|
||||
$ifetchpartner = 0;
|
||||
while ($ifetchpartner < $numofexpiredmembers)
|
||||
{
|
||||
$ifetchpartner++;
|
||||
$somethingdoneonpartnership = 0;
|
||||
$ifetchpartner = 0;
|
||||
while ($ifetchpartner < $numofexpiredmembers) {
|
||||
$ifetchpartner++;
|
||||
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
if (! empty($partnershipsprocessed[$obj->rowid])) continue;
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($obj) {
|
||||
if (! empty($partnershipsprocessed[$obj->rowid])) continue;
|
||||
|
||||
if ($somethingdoneonpartnership >= $MAXPERCALL)
|
||||
{
|
||||
dol_syslog("We reach the limit of ".$MAXPERCALL." partnership processed, so we quit loop for this batch doCancelStatusOfMemberPartnership to avoid to reach email quota.", LOG_WARNING);
|
||||
break;
|
||||
}
|
||||
if ($somethingdoneonpartnership >= $MAXPERCALL) {
|
||||
dol_syslog("We reach the limit of ".$MAXPERCALL." partnership processed, so we quit loop for this batch doCancelStatusOfMemberPartnership to avoid to reach email quota.", LOG_WARNING);
|
||||
break;
|
||||
}
|
||||
|
||||
$object = new Partnership($this->db);
|
||||
$object->fetch($obj->rowid);
|
||||
$object = new Partnership($this->db);
|
||||
$object->fetch($obj->rowid);
|
||||
|
||||
// Get expiration date
|
||||
$expirationdate = $obj->datefin;
|
||||
// Get expiration date
|
||||
$expirationdate = $obj->datefin;
|
||||
|
||||
if ($expirationdate && $expirationdate < $now) // If contract expired (we already had a test into main select, this is a security)
|
||||
{
|
||||
$somethingdoneonpartnership++;
|
||||
if ($expirationdate && $expirationdate < $now) { // If contract expired (we already had a test into main select, this is a security)
|
||||
$somethingdoneonpartnership++;
|
||||
|
||||
$result = $object->cancel($user, 0);
|
||||
// $conf->global->noapachereload = null;
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
$this->error = $object->error;
|
||||
if (is_array($object->errors) && count($object->errors)) {
|
||||
if (is_array($this->errors)) $this->errors = array_merge($this->errors, $object->errors);
|
||||
else $this->errors = $object->errors;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$partnershipsprocessed[$object->id]=$object->ref;
|
||||
$result = $object->cancel($user, 0);
|
||||
// $conf->global->noapachereload = null;
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$this->error = $object->error;
|
||||
if (is_array($object->errors) && count($object->errors)) {
|
||||
if (is_array($this->errors)) $this->errors = array_merge($this->errors, $object->errors);
|
||||
else $this->errors = $object->errors;
|
||||
}
|
||||
} else {
|
||||
$partnershipsprocessed[$object->id]=$object->ref;
|
||||
|
||||
// Send an email to inform member
|
||||
$labeltemplate = '(SendingEmailOnPartnershipCanceled)';
|
||||
// Send an email to inform member
|
||||
$labeltemplate = '(SendingEmailOnPartnershipCanceled)';
|
||||
|
||||
dol_syslog("Now we will send an email to member id=".$object->fk_member." with label ".$labeltemplate);
|
||||
dol_syslog("Now we will send an email to member id=".$object->fk_member." with label ".$labeltemplate);
|
||||
|
||||
// Send deployment email
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
||||
$formmail=new FormMail($this->db);
|
||||
// Send deployment email
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
||||
$formmail=new FormMail($this->db);
|
||||
|
||||
// Define output language
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
|
||||
if (! empty($newlang)) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
$outputlangs->loadLangs(array('main','member','partnership'));
|
||||
}
|
||||
// Define output language
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
|
||||
if (! empty($newlang)) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
$outputlangs->loadLangs(array('main','member','partnership'));
|
||||
}
|
||||
|
||||
$arraydefaultmessage=$formmail->getEMailTemplate($this->db, 'partnership_send', $user, $outputlangs, 0, 1, $labeltemplate);
|
||||
$arraydefaultmessage=$formmail->getEMailTemplate($this->db, 'partnership_send', $user, $outputlangs, 0, 1, $labeltemplate);
|
||||
|
||||
$substitutionarray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
|
||||
complete_substitutions_array($substitutionarray, $outputlangs, $object);
|
||||
$substitutionarray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
|
||||
complete_substitutions_array($substitutionarray, $outputlangs, $object);
|
||||
|
||||
$subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
|
||||
$msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
|
||||
$from = dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM, ' ', array(",")).' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
|
||||
$subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
|
||||
$msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
|
||||
$from = dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM, ' ', array(",")).' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
|
||||
|
||||
$adherent = new Adherent($this->db);
|
||||
$adherent->fetch($object->fk_member);
|
||||
$to = $adherent->email;
|
||||
$adherent = new Adherent($this->db);
|
||||
$adherent->fetch($object->fk_member);
|
||||
$to = $adherent->email;
|
||||
|
||||
$cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), '', '', 0, 1);
|
||||
$result = $cmail->sendfile();
|
||||
if (! $result || $cmail->error)
|
||||
{
|
||||
$erroremail .= ($erroremail ? ', ' : '').$cmail->error;
|
||||
$this->errors[] = $cmail->error;
|
||||
if (is_array($cmail->errors) && count($cmail->errors) > 0) $this->errors += $cmail->errors;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$this->error = $this->db->lasterror();
|
||||
}
|
||||
$cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), '', '', 0, 1);
|
||||
$result = $cmail->sendfile();
|
||||
if (! $result || $cmail->error) {
|
||||
$erroremail .= ($erroremail ? ', ' : '').$cmail->error;
|
||||
$this->errors[] = $cmail->error;
|
||||
if (is_array($cmail->errors) && count($cmail->errors) > 0) $this->errors += $cmail->errors;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
$this->error = $this->db->lasterror();
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
$this->output = $numofexpiredmembers.' expired partnership members found'."\n";
|
||||
if ($erroremail) $this->output.='. Got errors when sending some email : '.$erroremail;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
$this->output = "Rollback after error\n";
|
||||
$this->output.= $numofexpiredmembers.' expired partnership members found'."\n";
|
||||
if ($erroremail) $this->output.='. Got errors when sending some email : '.$erroremail;
|
||||
}
|
||||
if (! $error) {
|
||||
$this->db->commit();
|
||||
$this->output = $numofexpiredmembers.' expired partnership members found'."\n";
|
||||
if ($erroremail) $this->output.='. Got errors when sending some email : '.$erroremail;
|
||||
} else {
|
||||
$this->db->rollback();
|
||||
$this->output = "Rollback after error\n";
|
||||
$this->output.= $numofexpiredmembers.' expired partnership members found'."\n";
|
||||
if ($erroremail) $this->output.='. Got errors when sending some email : '.$erroremail;
|
||||
}
|
||||
|
||||
return ($error ? 1: 0);
|
||||
return ($error ? 1: 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -236,43 +220,42 @@ class PartnershipUtils
|
|||
{
|
||||
global $conf, $langs, $user;
|
||||
|
||||
$managedfor = $conf->global->PARTNERSHIP_IS_MANAGED_FOR;
|
||||
$managedfor = $conf->global->PARTNERSHIP_IS_MANAGED_FOR;
|
||||
|
||||
$partnership = new Partnership($this->db);
|
||||
$MAXPERCALL = (empty($conf->global->PARTNERSHIP_MAX_WARNING_BACKLINK_PER_CALL) ? 10 : $conf->global->PARTNERSHIP_MAX_WARNING_BACKLINK_PER_CALL); // Limit to 10 per call
|
||||
$partnership = new Partnership($this->db);
|
||||
$MAXPERCALL = (empty($conf->global->PARTNERSHIP_MAX_WARNING_BACKLINK_PER_CALL) ? 10 : $conf->global->PARTNERSHIP_MAX_WARNING_BACKLINK_PER_CALL); // Limit to 10 per call
|
||||
|
||||
$langs->loadLangs(array("partnership", "member"));
|
||||
$langs->loadLangs(array("partnership", "member"));
|
||||
|
||||
$error = 0;
|
||||
$erroremail = '';
|
||||
$this->output = '';
|
||||
$this->error = '';
|
||||
$partnershipsprocessed = array();
|
||||
$error = 0;
|
||||
$erroremail = '';
|
||||
$this->output = '';
|
||||
$this->error = '';
|
||||
$partnershipsprocessed = array();
|
||||
|
||||
$gracedelay=$conf->global->PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL;
|
||||
if ($gracedelay < 1)
|
||||
{
|
||||
$this->error='BadValueForDelayBeforeCancelCheckSetup';
|
||||
return -1;
|
||||
}
|
||||
$gracedelay=$conf->global->PARTNERSHIP_NBDAYS_AFTER_MEMBER_EXPIRATION_BEFORE_CANCEL;
|
||||
if ($gracedelay < 1) {
|
||||
$this->error='BadValueForDelayBeforeCancelCheckSetup';
|
||||
return -1;
|
||||
}
|
||||
|
||||
$fk_partner = ($managedfor == 'member') ? 'fk_member' : 'fk_soc';
|
||||
$fk_partner = ($managedfor == 'member') ? 'fk_member' : 'fk_soc';
|
||||
|
||||
dol_syslog(get_class($this)."::doWarningOfPartnershipIfDolibarrBacklinkNotfound Warning of partnership");
|
||||
dol_syslog(get_class($this)."::doWarningOfPartnershipIfDolibarrBacklinkNotfound Warning of partnership");
|
||||
|
||||
$now = dol_now();
|
||||
$datetotest = dol_time_plus_duree($now, -1 * abs($gracedelay), 'd');
|
||||
$now = dol_now();
|
||||
$datetotest = dol_time_plus_duree($now, -1 * abs($gracedelay), 'd');
|
||||
|
||||
$this->db->begin();
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "SELECT p.rowid, p.status, p.".$fk_partner;
|
||||
$sql .= ", p.last_check_backlink";
|
||||
$sql = "SELECT p.rowid, p.status, p.".$fk_partner;
|
||||
$sql .= ", p.last_check_backlink";
|
||||
|
||||
$sql .= ', partner.url, partner.email';
|
||||
$sql .= ', partner.url, partner.email';
|
||||
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."partnership as p";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."partnership as p";
|
||||
|
||||
if ($managedfor == 'member') {
|
||||
if ($managedfor == 'member') {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as partner on (partner.rowid = p.fk_member)";
|
||||
} else {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as partner on (partner.rowid = p.fk_soc)";
|
||||
|
|
@ -280,147 +263,131 @@ class PartnershipUtils
|
|||
|
||||
$sql .= " WHERE 1 = 1";
|
||||
$sql .= " AND p.".$fk_partner." > 0";
|
||||
$sql .= " AND p.status = ".$partnership::STATUS_ACCEPTED; // Only accepted not yet canceled
|
||||
$sql .= " AND (p.last_check_backlink IS NULL OR p.last_check_backlink <= '".$this->db->idate($now - 7 * 24 * 3600)."')"; // Every week, check that website contains a link to dolibarr.
|
||||
$sql .= $this->db->order('p.rowid','ASC');
|
||||
// Limit is managed into loop later
|
||||
$sql .= " AND p.status = ".$partnership::STATUS_ACCEPTED; // Only accepted not yet canceled
|
||||
$sql .= " AND (p.last_check_backlink IS NULL OR p.last_check_backlink <= '".$this->db->idate($now - 7 * 24 * 3600)."')"; // Every week, check that website contains a link to dolibarr.
|
||||
$sql .= $this->db->order('p.rowid', 'ASC');
|
||||
// Limit is managed into loop later
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$numofexpiredmembers = $this->db->num_rows($resql);
|
||||
$somethingdoneonpartnership = 0;
|
||||
$ifetchpartner = 0;
|
||||
while ($ifetchpartner < $numofexpiredmembers)
|
||||
{
|
||||
$ifetchpartner++;
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
$numofexpiredmembers = $this->db->num_rows($resql);
|
||||
$somethingdoneonpartnership = 0;
|
||||
$ifetchpartner = 0;
|
||||
while ($ifetchpartner < $numofexpiredmembers) {
|
||||
$ifetchpartner++;
|
||||
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
if (! empty($partnershipsprocessed[$obj->rowid])) continue;
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($obj) {
|
||||
if (! empty($partnershipsprocessed[$obj->rowid])) continue;
|
||||
|
||||
if ($somethingdoneonpartnership >= $MAXPERCALL)
|
||||
{
|
||||
dol_syslog("We reach the limit of ".$MAXPERCALL." partnership processed, so we quit loop for this batch doWarningOfPartnershipIfDolibarrBacklinkNotfound to avoid to reach email quota.", LOG_WARNING);
|
||||
break;
|
||||
}
|
||||
if ($somethingdoneonpartnership >= $MAXPERCALL) {
|
||||
dol_syslog("We reach the limit of ".$MAXPERCALL." partnership processed, so we quit loop for this batch doWarningOfPartnershipIfDolibarrBacklinkNotfound to avoid to reach email quota.", LOG_WARNING);
|
||||
break;
|
||||
}
|
||||
|
||||
$backlinkfound = 0;
|
||||
$backlinkfound = 0;
|
||||
|
||||
$object = new Partnership($this->db);
|
||||
$object->fetch($obj->rowid);
|
||||
$object = new Partnership($this->db);
|
||||
$object->fetch($obj->rowid);
|
||||
|
||||
if($managedfor == 'member'){
|
||||
$fk_partner = $object->fk_member;
|
||||
}else{
|
||||
$fk_partner = $object->fk_soc;
|
||||
}
|
||||
if ($managedfor == 'member') {
|
||||
$fk_partner = $object->fk_member;
|
||||
} else {
|
||||
$fk_partner = $object->fk_soc;
|
||||
}
|
||||
|
||||
$website = $obj->url;
|
||||
$website = $obj->url;
|
||||
|
||||
if(empty($website)){
|
||||
$websitenotfound .= ($websitenotfound ? ', ' : '').'Website not found for id="'.$fk_partner.'"'."\n";
|
||||
} else {
|
||||
$backlinkfound = $this->checkDolibarrBacklink($website);
|
||||
}
|
||||
if (empty($website)) {
|
||||
$websitenotfound .= ($websitenotfound ? ', ' : '').'Website not found for id="'.$fk_partner.'"'."\n";
|
||||
} else {
|
||||
$backlinkfound = $this->checkDolibarrBacklink($website);
|
||||
}
|
||||
|
||||
if(!$backlinkfound){
|
||||
$tmpcount = $object->count_last_url_check_error + 1;
|
||||
if (!$backlinkfound) {
|
||||
$tmpcount = $object->count_last_url_check_error + 1;
|
||||
|
||||
if($tmpcount == 3){ // Send Warning Email
|
||||
if ($tmpcount == 3) { // Send Warning Email
|
||||
if (!empty($obj->email)) {
|
||||
$emailnotfound .= ($emailnotfound ? ', ' : '').'Email not found for id="'.$fk_partner.'"'."\n";
|
||||
} else {
|
||||
$labeltemplate = '(SendingEmailOnPartnershipWillExpire)';
|
||||
|
||||
if (!empty($obj->email)){
|
||||
$emailnotfound .= ($emailnotfound ? ', ' : '').'Email not found for id="'.$fk_partner.'"'."\n";
|
||||
dol_syslog("Now we will send an email to partner id=".$fk_partner." with label ".$labeltemplate);
|
||||
|
||||
} else {
|
||||
// Send deployment email
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
||||
$formmail=new FormMail($this->db);
|
||||
|
||||
$labeltemplate = '(SendingEmailOnPartnershipWillExpire)';
|
||||
// Define output language
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
|
||||
if (! empty($newlang)) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
$outputlangs->loadLangs(array('main','member','partnership'));
|
||||
}
|
||||
|
||||
dol_syslog("Now we will send an email to partner id=".$fk_partner." with label ".$labeltemplate);
|
||||
$arraydefaultmessage=$formmail->getEMailTemplate($this->db, 'partnership_send', $user, $outputlangs, 0, 1, $labeltemplate);
|
||||
|
||||
// Send deployment email
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
||||
$formmail=new FormMail($this->db);
|
||||
$substitutionarray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
|
||||
complete_substitutions_array($substitutionarray, $outputlangs, $object);
|
||||
|
||||
// Define output language
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
|
||||
if (! empty($newlang)) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
$outputlangs->loadLangs(array('main','member','partnership'));
|
||||
}
|
||||
$subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
|
||||
$msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
|
||||
$from = dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM, ' ', array(",")).' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
|
||||
|
||||
$arraydefaultmessage=$formmail->getEMailTemplate($this->db, 'partnership_send', $user, $outputlangs, 0, 1, $labeltemplate);
|
||||
$to = $obj->email;
|
||||
|
||||
$substitutionarray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
|
||||
complete_substitutions_array($substitutionarray, $outputlangs, $object);
|
||||
$cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), '', '', 0, 1);
|
||||
$result = $cmail->sendfile();
|
||||
if (! $result || $cmail->error) {
|
||||
$erroremail .= ($erroremail ? ', ' : '').$cmail->error;
|
||||
$this->errors[] = $cmail->error;
|
||||
if (is_array($cmail->errors) && count($cmail->errors) > 0) $this->errors += $cmail->errors;
|
||||
}
|
||||
}
|
||||
} elseif ($tmpcount > 4) { // Cancel Partnership
|
||||
$object->status = $object::STATUS_CANCELED;
|
||||
$object->reason_decline_or_cancel = $langs->trans('BacklinkNotFoundOnPartnerWebsite');
|
||||
}
|
||||
|
||||
$subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
|
||||
$msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
|
||||
$from = dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM, ' ', array(",")).' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
|
||||
$object->count_last_url_check_error = $tmpcount;
|
||||
} else {
|
||||
$object->count_last_url_check_error = 0;
|
||||
$object->reason_decline_or_cancel = '';
|
||||
}
|
||||
|
||||
$to = $obj->email;
|
||||
$partnershipsprocessed[$object->id]=$object->ref;
|
||||
|
||||
$cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), '', '', 0, 1);
|
||||
$result = $cmail->sendfile();
|
||||
if (! $result || $cmail->error)
|
||||
{
|
||||
$erroremail .= ($erroremail ? ', ' : '').$cmail->error;
|
||||
$this->errors[] = $cmail->error;
|
||||
if (is_array($cmail->errors) && count($cmail->errors) > 0) $this->errors += $cmail->errors;
|
||||
}
|
||||
}
|
||||
$object->last_check_backlink = $this->db->idate($now);
|
||||
|
||||
$object->update($user);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
$this->error = $this->db->lasterror();
|
||||
}
|
||||
|
||||
} elseif($tmpcount > 4) { // Cancel Partnership
|
||||
$object->status = $object::STATUS_CANCELED;
|
||||
$object->reason_decline_or_cancel = $langs->trans('BacklinkNotFoundOnPartnerWebsite');
|
||||
}
|
||||
if (! $error) {
|
||||
$this->db->commit();
|
||||
$this->output = $numofexpiredmembers.' partnership checked'."\n";
|
||||
if ($erroremail) $this->output.='. Got errors when sending some email : '.$erroremail."\n";
|
||||
if ($emailnotfound) $this->output.='. Email not found for some partner : '.$emailnotfound."\n";
|
||||
if ($websitenotfound) $this->output.='. Website not found for some partner : '.$websitenotfound."\n";
|
||||
} else {
|
||||
$this->db->rollback();
|
||||
$this->output = "Rollback after error\n";
|
||||
$this->output.= $numofexpiredmembers.' partnership checked'."\n";
|
||||
if ($erroremail) $this->output.='. Got errors when sending some email : '.$erroremail."\n";
|
||||
if ($emailnotfound) $this->output.='. Email not found for some partner : '.$emailnotfound."\n";
|
||||
if ($websitenotfound) $this->output.='. Website not found for some partner : '.$websitenotfound."\n";
|
||||
}
|
||||
|
||||
$object->count_last_url_check_error = $tmpcount;
|
||||
|
||||
} else {
|
||||
$object->count_last_url_check_error = 0;
|
||||
$object->reason_decline_or_cancel = '';
|
||||
}
|
||||
|
||||
$partnershipsprocessed[$object->id]=$object->ref;
|
||||
|
||||
$object->last_check_backlink = $this->db->idate($now);
|
||||
|
||||
$object->update($user);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$this->error = $this->db->lasterror();
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
$this->output = $numofexpiredmembers.' partnership checked'."\n";
|
||||
if ($erroremail) $this->output.='. Got errors when sending some email : '.$erroremail."\n";
|
||||
if ($emailnotfound) $this->output.='. Email not found for some partner : '.$emailnotfound."\n";
|
||||
if ($websitenotfound) $this->output.='. Website not found for some partner : '.$websitenotfound."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
$this->output = "Rollback after error\n";
|
||||
$this->output.= $numofexpiredmembers.' partnership checked'."\n";
|
||||
if ($erroremail) $this->output.='. Got errors when sending some email : '.$erroremail."\n";
|
||||
if ($emailnotfound) $this->output.='. Email not found for some partner : '.$emailnotfound."\n";
|
||||
if ($websitenotfound) $this->output.='. Website not found for some partner : '.$websitenotfound."\n";
|
||||
}
|
||||
|
||||
return ($error ? 1: 0);
|
||||
return ($error ? 1: 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -439,8 +406,8 @@ class PartnershipUtils
|
|||
$webcontent = '';
|
||||
|
||||
// $website = 'https://nextgestion.com/'; // For Test
|
||||
$tmpgeturl = getURLContent($website);
|
||||
if ($tmpgeturl['curl_error_no']) {
|
||||
$tmpgeturl = getURLContent($website);
|
||||
if ($tmpgeturl['curl_error_no']) {
|
||||
$error++;
|
||||
dol_syslog('Error getting '.$website.': '.$tmpgeturl['curl_error_msg']);
|
||||
} elseif ($tmpgeturl['http_code'] != '200') {
|
||||
|
|
@ -454,19 +421,18 @@ class PartnershipUtils
|
|||
$xpath = new DOMXPath($dom);
|
||||
$hrefs = $xpath->evaluate("//a");
|
||||
|
||||
for($i = 0; $i < $hrefs->length; $i++){
|
||||
$href = $hrefs->item($i);
|
||||
$url = $href->getAttribute('href');
|
||||
$url = filter_var($url, FILTER_SANITIZE_URL);
|
||||
if(!filter_var($url, FILTER_VALIDATE_URL) === false){
|
||||
$webcontent .= $url;
|
||||
}
|
||||
for ($i = 0; $i < $hrefs->length; $i++) {
|
||||
$href = $hrefs->item($i);
|
||||
$url = $href->getAttribute('href');
|
||||
$url = filter_var($url, FILTER_SANITIZE_URL);
|
||||
if (!filter_var($url, FILTER_VALIDATE_URL) === false) {
|
||||
$webcontent .= $url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($webcontent && !empty($conf->global->PARTNERSHIP_BACKLINKS_TO_CHECK) && preg_match('/'.$conf->global->PARTNERSHIP_BACKLINKS_TO_CHECK.'/', $webcontent))
|
||||
{
|
||||
$found = 1;
|
||||
}
|
||||
|
||||
if ($webcontent && !empty($conf->global->PARTNERSHIP_BACKLINKS_TO_CHECK) && preg_match('/'.$conf->global->PARTNERSHIP_BACKLINKS_TO_CHECK.'/', $webcontent)) {
|
||||
$found = 1;
|
||||
}
|
||||
|
||||
return $found;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user