Remove the old deprecated code of doActions in canvas. The doActions of

hooks are already available and are better.
This commit is contained in:
Laurent Destailleur 2018-03-16 09:58:46 +01:00
parent 8bfac66f04
commit eb5d5d07ec
5 changed files with 2 additions and 552 deletions

View File

@ -15,6 +15,8 @@ Following changes may create regressions for some external modules, but were nec
* Remove triggers *_CLONE. The trigger CREATE with context 'createfromclone' is already called so this is
a duplicated feature. Cloning is not a business event, the business event is CREATE, so no trigger required.
* PHP 5.3 is no more supported. Minimum PHP is now 5.4+
* Remove the old deprecated code of doActions in canvas. The doActions of hooks are already available and are better.
***** ChangeLog for 7.0.0 compared to 6.0.5 *****

View File

@ -97,141 +97,6 @@ abstract class ActionsAdherentCardCommon
//}
}
/**
* doActions of a canvas is not the doActions of the hook
* @deprecated Use the doActions of hooks instead of this.
*
* @param string $action Type of action
* @param int $id Id of object
* @return void
*/
function doActions(&$action, $id)
{
global $conf, $user, $langs;
// Creation utilisateur depuis Adherent
if ($action == 'confirm_create_user' && GETPOST("confirm") == 'yes')
{
// Recuperation adherent actuel
$result = $this->object->fetch($id);
if ($result > 0)
{
$this->db->begin();
// Creation user
$nuser = new User($this->db);
$result=$nuser->create_from_member($this->object,GETPOST("login"));
if ($result > 0)
{
$result2=$nuser->setPassword($user,GETPOST("password"),0,1,1);
if ($result2)
{
$this->db->commit();
}
else
{
$this->db->rollback();
}
}
else
{
$this->errors[]=$nuser->error;
$this->db->rollback();
}
}
else
{
$this->errors=$this->object->errors;
}
}
// Creation adherent
if ($action == 'add')
{
$this->assign_post();
if (! $_POST["name"])
{
array_push($this->errors,$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label")));
$action = 'create';
}
if ($_POST["name"])
{
$id = $this->object->create($user);
if ($id > 0)
{
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit;
}
else
{
$this->errors=$this->object->errors;
$action = 'create';
}
}
}
if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
{
$result=$this->object->fetch($id);
$this->object->old_name = $_POST["old_name"];
$this->object->old_firstname = $_POST["old_firstname"];
$result = $this->object->delete(0, $user, 0);
if ($result > 0)
{
header("Location: list.php");
exit;
}
else
{
$this->errors=$this->object->errors;
}
}
if ($action == 'update')
{
if ($_POST["cancel"])
{
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$this->object->id);
exit;
}
if (empty($_POST["name"]))
{
$this->error=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
$action = 'edit';
}
if (empty($this->error))
{
$this->object->fetch($_POST["adherentid"]);
$this->object->oldcopy = clone $this->object;
$this->assign_post();
$result = $this->object->update($_POST["adherentid"], $user);
if ($result > 0)
{
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$this->object->id);
exit;
}
else
{
$this->errors=$this->object->errors;
$action = 'edit';
}
}
}
}
/**
* Set content of ->tpl array, to use into template
*

View File

@ -93,141 +93,6 @@ abstract class ActionsContactCardCommon
//}
}
/**
* doActions of a canvas is not the doActions of the hook
* @deprecated Use the doActions of hooks instead of this.
*
* @param string $action Type of action
* @param int $id Id of object
* @return void
*/
function doActions(&$action, $id)
{
global $conf, $user, $langs;
// Creation utilisateur depuis contact
if ($action == 'confirm_create_user' && GETPOST("confirm") == 'yes')
{
// Recuperation contact actuel
$result = $this->object->fetch($id);
if ($result > 0)
{
$this->db->begin();
// Creation user
$nuser = new User($this->db);
$result=$nuser->create_from_contact($this->object,$_POST["login"]);
if ($result > 0)
{
$result2=$nuser->setPassword($user,$_POST["password"],0,1,1);
if ($result2)
{
$this->db->commit();
}
else
{
$this->db->rollback();
}
}
else
{
$this->errors=$nuser->error;
$this->db->rollback();
}
}
else
{
$this->errors=$this->object->errors;
}
}
// Creation contact
if ($action == 'add')
{
$this->assign_post();
if (! $_POST["name"])
{
array_push($this->errors,$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label")));
$action = 'create';
}
if ($_POST["name"])
{
$id = $this->object->create($user);
if ($id > 0)
{
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit;
}
else
{
$this->errors=$this->object->errors;
$action = 'create';
}
}
}
if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
{
$result=$this->object->fetch($id);
$this->object->old_name = $_POST["old_name"];
$this->object->old_firstname = $_POST["old_firstname"];
$result = $this->object->delete();
if ($result > 0)
{
header("Location: list.php");
exit;
}
else
{
$this->errors=$this->object->errors;
}
}
if ($action == 'update')
{
if ($_POST["cancel"])
{
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$this->object->id);
exit;
}
if (empty($_POST["name"]))
{
$this->error=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
$action = 'edit';
}
if (empty($this->error))
{
$this->object->fetch($_POST["contactid"]);
$this->object->oldcopy = clone $this->object;
$this->assign_post();
$result = $this->object->update($_POST["contactid"], $user);
if ($result > 0)
{
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$this->object->id);
exit;
}
else
{
$this->errors=$this->object->errors;
$action = 'edit';
}
}
}
}
/**
* Set content of ->tpl array, to use into template
*

View File

@ -87,271 +87,6 @@ abstract class ActionsCardCommon
$this->object = $object;
}
/**
* doActions of a canvas is not the doActions of the hook
* @deprecated Use the doActions of hooks instead of this.
*
* @param int $action Action code
* @return void
*/
function doActions(&$action)
{
global $conf, $user, $langs;
if ($_POST["getcustomercode"])
{
// We defined value code_client
$_POST["code_client"]="Acompleter";
}
if ($_POST["getsuppliercode"])
{
// We defined value code_fournisseur
$_POST["code_fournisseur"]="Acompleter";
}
// Add new third party
if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
&& ($action == 'add' || $action == 'update'))
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$error=0;
if (GETPOST("private") == 1)
{
$this->object->particulier = GETPOST("private");
$this->object->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["firstname"].' '.$_POST["lastname"]):trim($_POST["lastname"].' '.$_POST["firstname"]);
$this->object->civility_id = $_POST["civility_id"];
// Add non official properties
$this->object->name_bis = $_POST["lastname"];
$this->object->firstname = $_POST["firstname"];
}
else
{
$this->object->name = $_POST["nom"];
}
$this->object->address = $_POST["adresse"];
$this->object->zip = $_POST["zipcode"];
$this->object->town = $_POST["town"];
$this->object->country_id = $_POST["country_id"];
$this->object->state_id = $_POST["state_id"];
$this->object->phone = $_POST["tel"];
$this->object->fax = $_POST["fax"];
$this->object->email = trim($_POST["email"]);
$this->object->url = $_POST["url"];
$this->object->idprof1 = $_POST["idprof1"];
$this->object->idprof2 = $_POST["idprof2"];
$this->object->idprof3 = $_POST["idprof3"];
$this->object->idprof4 = $_POST["idprof4"];
$this->object->prefix_comm = $_POST["prefix_comm"];
$this->object->code_client = $_POST["code_client"];
$this->object->code_fournisseur = $_POST["code_fournisseur"];
$this->object->capital = $_POST["capital"];
$this->object->barcode = $_POST["barcode"];
$this->object->canvas = GETPOST("canvas");
$this->object->tva_assuj = $_POST["assujtva_value"];
// Local Taxes
$this->object->localtax1_assuj = $_POST["localtax1assuj_value"];
$this->object->localtax2_assuj = $_POST["localtax2assuj_value"];
$this->object->tva_intra = $_POST["tva_intra"];
$this->object->forme_juridique_code = $_POST["forme_juridique_code"];
$this->object->effectif_id = $_POST["effectif_id"];
if (GETPOST("private") == 1)
{
$this->object->typent_id = dol_getIdFromCode($db,'TE_PRIVATE','c_typent');
}
else
{
$this->object->typent_id = $_POST["typent_id"];
}
$this->object->client = $_POST["client"];
$this->object->fournisseur = $_POST["fournisseur"];
$this->object->commercial_id = $_POST["commercial_id"];
$this->object->default_lang = $_POST["default_lang"];
// Check parameters
if (empty($_POST["cancel"]))
{
if (! empty($this->object->email) && ! isValidEMail($this->object->email))
{
$error = 1;
$langs->load("errors");
$this->error = $langs->trans("ErrorBadEMail",$this->object->email);
$action = ($action == 'add' ? 'create' : 'edit');
}
if (! empty($this->object->url) && ! isValidUrl($this->object->url))
{
$error = 1;
$langs->load("errors");
$this->error = $langs->trans("ErrorBadUrl",$this->object->url);
$action = ($action == 'add' ? 'create' : 'edit');
}
if ($this->object->fournisseur && ! $conf->fournisseur->enabled)
{
$error = 1;
$langs->load("errors");
$this->error = $langs->trans("ErrorSupplierModuleNotEnabled");
$action = ($action == 'add' ? 'create' : 'edit');
}
}
if (! $error)
{
if ($action == 'add')
{
$this->db->begin();
if (empty($this->object->client)) $this->object->code_client='';
if (empty($this->object->fournisseur)) $this->object->code_fournisseur='';
$result = $this->object->create($user);
if ($result >= 0)
{
if ($this->object->particulier)
{
dol_syslog(get_class($this)."::doActions This thirdparty is a personal people",LOG_DEBUG);
$contact=new Contact($this->db);
$contact->civility_id = $this->object->civility_id;
$contact->name = $this->object->name_bis;
$contact->firstname = $this->object->firstname;
$contact->address = $this->object->address;
$contact->zip = $this->object->zip;
$contact->town = $this->object->town;
$contact->country_id = $this->object->country_id;
$contact->socid = $this->object->id; // fk_soc
$contact->status = 1;
$contact->email = $this->object->email;
$contact->priv = 0;
$result=$contact->create($user);
}
}
else
{
$this->errors=$this->object->errors;
}
if ($result >= 0)
{
$this->db->commit();
if ( $this->object->client == 1 )
{
header("Location: ".DOL_URL_ROOT."/comm/card.php?socid=".$this->object->id);
return;
}
else
{
if ( $this->object->fournisseur == 1 )
{
header("Location: ".DOL_URL_ROOT."/fourn/card.php?socid=".$this->object->id);
return;
}
else
{
header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id);
return;
}
}
}
else
{
$this->db->rollback();
$this->errors=$this->object->errors;
$action = 'create';
}
}
if ($action == 'update')
{
if ($_POST["cancel"])
{
header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id);
exit;
}
$oldsoccanvas = clone $this->object;
// To avoid setting code if third party is not concerned. But if it had values, we keep them.
if (empty($this->object->client) && empty($oldsoccanvas->code_client)) $this->object->code_client='';
if (empty($this->object->fournisseur) && empty($oldsoccanvas->code_fournisseur)) $this->object->code_fournisseur='';
$result = $this->object->update($this->object->id, $user, 1, $oldsoccanvas->codeclient_modifiable(), $oldsoccanvas->codefournisseur_modifiable());
if ($result >= 0)
{
header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id);
exit;
}
else
{
$reload = 0;
$this->errors = $this->object->errors;
$action = "edit";
}
}
}
}
if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
{
$result = $this->object->delete($this->object->id);
if ($result >= 0)
{
header("Location: ".DOL_URL_ROOT."/societe/list.php?delsoc=".$this->object->name."");
exit;
}
else
{
$reload = 0;
$this->errors=$this->object->errors;
$action = '';
}
}
/*
* Generate document
*/
if ($action == 'builddoc') // En get ou en post
{
if (is_numeric(GETPOST('model')))
{
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
}
else
{
require_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
$this->object->fetch_thirdparty();
// Define output language
$outputlangs = $langs;
$newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$this->object->default_lang;
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
$result=thirdparty_doc_create($this->db, $this->object->id, '', GETPOST('model','alpha'), $outputlangs);
if ($result <= 0)
{
dol_print_error($this->db,$result);
exit;
}
}
}
}
/**
* Assign custom values for canvas (for example into this->tpl to be used by templates)
*

View File

@ -67,23 +67,6 @@ class ActionsCardCompany extends ActionsCardCommon
}
/**
* doActions of a canvas is not the doActions of the hook
* @deprecated Use the doActions of hooks instead of this.
*
* @param string $action Type of action
* @param int $id Id of object
* @return int <0 if KO, >0 if OK
*/
function doActions(&$action, $id)
{
$ret = $this->getObject($id);
$return = parent::doActions($action);
return $return;
}
/**
* Assign custom values for canvas (for example into this->tpl to be used by templates)
*