Fix: remove unused parameters

Fix: use dol_clone instead fetch
This commit is contained in:
Regis Houssin 2011-12-12 13:42:19 +01:00
parent 55bce13bfb
commit ec327c5330
2 changed files with 37 additions and 49 deletions

View File

@ -99,23 +99,25 @@ $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);
// Action clone object // Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes') if ($action == 'confirm_clone' && $confirm == 'yes')
{ {
if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers') ) if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
{ {
$mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>'; $mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>';
} }
else else
{ {
$result=$object->createFromClone($id,0,GETPOST('socid'),$hookmanager); if ($object->fetch($id) > 0)
if ($result > 0)
{ {
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); $result=$object->createFromClone(GETPOST('socid'),$hookmanager);
exit; if ($result > 0)
} {
else header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
{ exit;
$mesg=$object->error; }
$action=''; else
//$_GET['id']=$_REQUEST['id']; {
$mesg=$object->error;
$action='';
}
} }
} }
} }

View File

@ -836,53 +836,45 @@ class Propal extends CommonObject
/** /**
* Load an object from its id and create a new one in database * Load an object from its id and create a new one in database
* *
* @param int $fromid Id of object to clone
* @param int $invertdetail Reverse sign of amounts for lines
* @param int $socid Id of thirdparty * @param int $socid Id of thirdparty
* @param HookManager $hookmanager Hook manager instance * @param HookManager $hookmanager Hook manager instance
* @return int New id of clone * @return int New id of clone
*/ */
function createFromClone($fromid,$invertdetail=0,$socid=0,$hookmanager=false) function createFromClone($socid=0,$hookmanager=false)
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
$error=0; $error=0;
$now=dol_now(); $now=dol_now();
$object=new Propal($this->db);
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
$object->fetch($fromid); $objFrom = dol_clone($this);
$objFrom = $object;
$objsoc=new Societe($this->db); $objsoc=new Societe($this->db);
// Change socid if needed // Change socid if needed
if (! empty($socid) && $socid != $object->socid) if (! empty($socid) && $socid != $this->socid)
{ {
if ($objsoc->fetch($socid)>0) if ($objsoc->fetch($socid) > 0)
{ {
$object->socid = $objsoc->id; $this->socid = $objsoc->id;
$object->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); $this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
$object->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); $this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
$object->fk_project = ''; $this->fk_project = '';
$object->fk_delivery_address = ''; $this->fk_delivery_address = '';
} }
// TODO Change product price if multi-prices // TODO Change product price if multi-prices
} }
else else
{ {
$objsoc->fetch($object->socid); $objsoc->fetch($this->socid);
} }
$object->id=0; $this->id=0;
$object->statut=0; $this->statut=0;
$objsoc->fetch($object->socid);
if (empty($conf->global->PROPALE_ADDON) || ! is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php")) if (empty($conf->global->PROPALE_ADDON) || ! is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php"))
{ {
@ -891,28 +883,22 @@ class Propal extends CommonObject
} }
// Clear fields // Clear fields
$object->user_author = $user->id; $this->user_author = $user->id;
$object->user_valid = ''; $this->user_valid = '';
$object->date = ''; $this->date = '';
$object->datep = $now; $this->datep = $now;
$object->fin_validite = $object->datep + ($this->duree_validite * 24 * 3600); $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
$object->ref_client = ''; $this->ref_client = '';
// Set ref // Set ref
require_once(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php"); require_once(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php");
$obj = $conf->global->PROPALE_ADDON; $obj = $conf->global->PROPALE_ADDON;
$modPropale = new $obj; $modPropale = new $obj;
$object->ref = $modPropale->getNextValue($objsoc,$object); $this->ref = $modPropale->getNextValue($objsoc,$this);
// Create clone // Create clone
$result=$object->create($user); $result=$this->create($user);
if ($result < 0) $error++;
// Other options
if ($result < 0)
{
$this->error=$object->error;
$error++;
}
if (! $error) if (! $error)
{ {
@ -921,14 +907,14 @@ class Propal extends CommonObject
{ {
$parameters=array('objFrom'=>$objFrom); $parameters=array('objFrom'=>$objFrom);
$action=''; $action='';
$reshook=$hookmanager->executeHooks('createfrom',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) $error++; if ($reshook < 0) $error++;
} }
// Appel des triggers // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers('PROPAL_CLONE',$object,$user,$langs,$conf); $result=$interface->run_triggers('PROPAL_CLONE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
} }
@ -937,7 +923,7 @@ class Propal extends CommonObject
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();
return $object->id; return $this->id;
} }
else else
{ {