Skip to content

Commit

Permalink
Signatures of methods createFromClone() has been standardized. All
Browse files Browse the repository at this point in the history
methods requires the object User as first parameter.
  • Loading branch information
eldy committed Apr 25, 2019
1 parent e089594 commit 091132d
Show file tree
Hide file tree
Showing 44 changed files with 138 additions and 173 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -28,6 +28,7 @@ Following changes may create regressions for some external modules, but were nec
* Files for variables of themes were renamed from graph-color.php into theme_vars.inc.php to match naming
convention of extension .inc.php for files to be included.
* All methods set_draft() were renamed into setDraft().
* Signatures of methods createFromClone() has been standardized. All methods requires the object User as first parameter.
* Removed deprecated function function test_sql_and_script_inject that was replaced with testSqlAndScriptInject.
* Method load_measuring_units were renamed into selectMeasuringUnits and select_measuring_units was deprecated.
* Hidden option CHANGE_ORDER_CONCAT_DESCRIPTION were renamed into MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION.
Expand Down
10 changes: 4 additions & 6 deletions htdocs/accountancy/class/bookkeeping.class.php
Expand Up @@ -1409,16 +1409,14 @@ public function deleteMvtNum($piecenum)
/**
* Load an object from its id and create a new one in database
*
* @param int $fromid Id of object to clone
*
* @return int New id of clone
* @param User $user User making the clone
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone($fromid)
public function createFromClone(User $user, $fromid)
{
dol_syslog(__METHOD__, LOG_DEBUG);

global $user;

$error = 0;
$object = new BookKeeping($this->db);

Expand Down
9 changes: 6 additions & 3 deletions htdocs/admin/emailcollector_card.php
Expand Up @@ -604,11 +604,14 @@ function init_myfunc()

if (empty($reshook))
{
print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=edit">' . $langs->trans("Edit") . '</a>' . "\n";
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=edit">' . $langs->trans("Edit") . '</a></div>';

print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=collect">' . $langs->trans("CollectNow") . '</a>' . "\n";
// Clone
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&amp;socid=' . $object->socid . '&amp;action=clone&amp;object=order">' . $langs->trans("ToClone") . '</a></div>';

print '<a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=delete">' . $langs->trans('Delete') . '</a>' . "\n";
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=collect">' . $langs->trans("CollectNow") . '</a></div>';

print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=delete">' . $langs->trans('Delete') . '</a></div>';
}
print '</div>' . "\n";
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/comm/action/card.php
Expand Up @@ -164,7 +164,7 @@
reset($object->socpeopleassigned);
$object->contactid = key($object->socpeopleassigned);
}
$result = $object->createFromClone(GETPOST('fk_userowner'), GETPOST('socid'));
$result = $object->createFromClone($user, GETPOST('fk_userowner'), GETPOST('socid'));
if ($result > 0) {
header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $result);
exit();
Expand Down
28 changes: 7 additions & 21 deletions htdocs/comm/action/class/actioncomm.class.php
Expand Up @@ -87,14 +87,14 @@ class ActionComm extends CommonObject
* @var string Agenda event label
*/
public $label;

/**
* Date creation record (datec)
*
* @var integer
*/
public $datec;

/**
* Date modification record (tms)
*
Expand Down Expand Up @@ -129,14 +129,14 @@ class ActionComm extends CommonObject
* @var int
*/
public $usermodid;

/**
* Date action start (datep)
*
* @var integer
*/
public $datep;

/**
* Date action end (datep2)
*
Expand Down Expand Up @@ -504,13 +504,13 @@ public function add(User $user, $notrigger = 0)
/**
* Load an object from its id and create a new one in database
*
* @param user $fuser Object user making action
* @param User $fuser Object user making action
* @param int $socid Id of thirdparty
* @return int New id of clone
*/
public function createFromClone($fuser, $socid)
public function createFromClone(User $fuser, $socid)
{
global $db, $user, $langs, $conf, $hookmanager;
global $db, $conf, $hookmanager;

$error=0;
$now=dol_now();
Expand All @@ -529,20 +529,6 @@ public function createFromClone($fuser, $socid)

$this->id=0;

if (!is_object($fuser))
{
if ($fuser > 0)
{
$u = new User($db);
$u->fetch($fuser);
$fuser = $u;
}
else
{
$fuser = $user;
}
}

// Create clone
$this->context['createfromclone']='createfromclone';
$result=$this->create($fuser);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/comm/mailing/card.php
Expand Up @@ -97,7 +97,7 @@
}
else
{
$result=$object->createFromClone($object->id, $_REQUEST["clone_content"], $_REQUEST["clone_receivers"]);
$result=$object->createFromClone($user, $object->id, $_REQUEST["clone_content"], $_REQUEST["clone_receivers"]);
if ($result > 0)
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
Expand Down
5 changes: 3 additions & 2 deletions htdocs/comm/mailing/class/mailing.class.php
Expand Up @@ -266,14 +266,15 @@ public function fetch($rowid)
/**
* Load an object from its id and create a new one in database
*
* @param User $user User making the clone
* @param int $fromid Id of object to clone
* @param int $option1 1=Copy content, 0=Forget content
* @param int $option2 Not used
* @return int New id of clone
*/
public function createFromClone($fromid, $option1, $option2)
public function createFromClone(User $user, $fromid, $option1, $option2)
{
global $user,$langs;
global $langs;

$error=0;

Expand Down
2 changes: 1 addition & 1 deletion htdocs/comm/propal/card.php
Expand Up @@ -192,7 +192,7 @@
}
}

$result = $object->createFromClone($socid);
$result = $object->createFromClone($user, $socid);
if ($result > 0) {
header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $result);
exit();
Expand Down
13 changes: 7 additions & 6 deletions htdocs/comm/propal/class/propal.class.php
Expand Up @@ -473,7 +473,7 @@ public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0.0, $txloca

// Check parameters
if ($type < 0) return -1;

if ($date_start && $date_end && $date_start > $date_end) {
$langs->load("errors");
$this->error=$langs->trans('ErrorStartDateGreaterEnd');
Expand Down Expand Up @@ -690,7 +690,7 @@ public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocalt
if (empty($qty) && empty($special_code)) $special_code=3; // Set option tag
if (! empty($qty) && $special_code == 3) $special_code=0; // Remove option tag
if (empty($type)) $type=0;

if ($date_start && $date_end && $date_start > $date_end) {
$langs->load("errors");
$this->error=$langs->trans('ErrorStartDateGreaterEnd');
Expand Down Expand Up @@ -1226,12 +1226,13 @@ public function create_from($user)
/**
* Load an object from its id and create a new one in database
*
* @param int $socid Id of thirdparty
* @return int New id of clone
* @param User $user User making the clone
* @param int $socid Id of thirdparty
* @return int New id of clone
*/
public function createFromClone($socid = 0)
public function createFromClone(User $user, $socid = 0)
{
global $user,$conf,$hookmanager;
global $conf,$hookmanager;

dol_include_once('/projet/class/project.class.php');

Expand Down
2 changes: 1 addition & 1 deletion htdocs/commande/card.php
Expand Up @@ -142,7 +142,7 @@
// Because createFromClone modifies the object, we must clone it so that we can restore it later
$orig = clone $object;

$result=$object->createFromClone($socid);
$result=$object->createFromClone($user, $socid);
if ($result > 0)
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
Expand Down
7 changes: 4 additions & 3 deletions htdocs/commande/class/commande.class.php
Expand Up @@ -1070,10 +1070,11 @@ public function create($user, $notrigger = 0)
/**
* Load an object from its id and create a new one in database
*
* @param int $socid Id of thirdparty
* @return int New id of clone
* @param User $user User making the clone
* @param int $socid Id of thirdparty
* @return int New id of clone
*/
public function createFromClone($socid = 0)
public function createFromClone(User $user, $socid = 0)
{
global $conf, $user,$hookmanager;

Expand Down
9 changes: 4 additions & 5 deletions htdocs/compta/bank/class/bankcateg.class.php
Expand Up @@ -269,13 +269,12 @@ public function delete(User $user, $notrigger = 0)
/**
* Load an object from its id and create a new one in database
*
* @param int $fromid Id of object to clone
* @return int New id of clone
* @param User $user User making the clone
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone($fromid)
public function createFromClone(User $user, $fromid)
{
global $user;

$error = 0;

$object = new BankCateg($this->db);
Expand Down
5 changes: 2 additions & 3 deletions htdocs/compta/facture/class/paymentterm.class.php
Expand Up @@ -393,13 +393,12 @@ public function delete($user, $notrigger = 0)
/**
* Load an object from its id and create a new one in database
*
* @param User $user User making the clone
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone($fromid)
public function createFromClone(User $user, $fromid)
{
global $user,$langs;

$error=0;

$object=new PaymentTerm($this->db);
Expand Down
9 changes: 4 additions & 5 deletions htdocs/compta/sociales/class/cchargesociales.class.php
Expand Up @@ -346,15 +346,14 @@ public function delete(User $user, $notrigger = false)
/**
* Load an object from its id and create a new one in database
*
* @param int $fromid Id of object to clone
*
* @return int New id of clone
* @param User $user User making the clone
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone($fromid)
public function createFromClone(User $user, $fromid)
{
dol_syslog(__METHOD__, LOG_DEBUG);

global $user;
$error = 0;
$object = new Cchargesociales($this->db);

Expand Down
Expand Up @@ -448,13 +448,12 @@ public function delete($user, $notrigger = 0)
/**
* Load an object from its id and create a new one in database
*
* @param User $user User making the clone
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone($fromid)
public function createFromClone(User $user, $fromid)
{
global $user,$langs;

$error=0;

$object=new PaymentSocialContribution($this->db);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/contrat/card.php
Expand Up @@ -1072,7 +1072,7 @@
else
{
if ($object->id > 0) {
$result = $object->createFromClone($socid);
$result = $object->createFromClone($user, $socid);
if ($result > 0) {
header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $result);
exit();
Expand Down
11 changes: 6 additions & 5 deletions htdocs/contrat/class/contrat.class.php
Expand Up @@ -2388,13 +2388,14 @@ public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
/**
* Load an object from its id and create a new one in database
*
* @param int $socid Id of thirdparty
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int New id of clone
* @param User $user User making the clone
* @param int $socid Id of thirdparty
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int New id of clone
*/
public function createFromClone($socid = 0, $notrigger = 0)
public function createFromClone(User $user, $socid = 0, $notrigger = 0)
{
global $db, $user, $langs, $conf, $hookmanager, $extrafields;
global $db, $langs, $conf, $hookmanager, $extrafields;

dol_include_once('/projet/class/project.class.php');

Expand Down
17 changes: 0 additions & 17 deletions htdocs/core/actions_addupdatedelete.inc.php
Expand Up @@ -195,23 +195,6 @@
}
}

// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd)
{
$objectutil = dol_clone($object); // To avoid to denaturate loaded object when setting some properties for clone
//$objectutil->date = dol_mktime(12, 0, 0, GETPOST('newdatemonth', 'int'), GETPOST('newdateday', 'int'), GETPOST('newdateyear', 'int'));

$result = $objectutil->createFromClone($id);
if ($result > 0) {
header("Location: " . $_SERVER['PHP_SELF'] . '?facid=' . $result);
exit();
} else {
$langs->load("errors");
setEventMessages($objectutil->error, $objectutil->errors, 'errors');
$action = '';
}
}

// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd)
{
Expand Down
9 changes: 4 additions & 5 deletions htdocs/core/class/ctyperesource.class.php
Expand Up @@ -404,15 +404,14 @@ public function delete(User $user, $notrigger = false)
/**
* Load an object from its id and create a new one in database
*
* @param int $fromid Id of object to clone
*
* @return int New id of clone
* @param User $user User making the clone
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone($fromid)
public function createFromClone(User $user, $fromid)
{
dol_syslog(__METHOD__, LOG_DEBUG);

global $user;
$error = 0;
$object = new Ctyperesource($this->db);

Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/modules/modEmailCollector.class.php
Expand Up @@ -64,7 +64,7 @@ public function __construct($db)
$this->descriptionlong = "EmailCollectorDescription";

// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
$this->version = 'experimental';
$this->version = 'dolibarr';
// Key used in llx_const table to save module status enabled/disabled (where DAV is value of property name of module in uppercase)
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
// Name of image file used for this module.
Expand Down
5 changes: 2 additions & 3 deletions htdocs/cron/class/cronjob.class.php
Expand Up @@ -736,13 +736,12 @@ public function delete($user, $notrigger = 0)
/**
* Load an object from its id and create a new one in database
*
* @param User $user User making the clone
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone($fromid)
public function createFromClone(User $user, $fromid)
{
global $user,$langs;

$error=0;

$object=new Cronjob($this->db);
Expand Down

0 comments on commit 091132d

Please sign in to comment.