Fix: uniformize structure
Works on migration of linked tables
This commit is contained in:
parent
d19046df94
commit
e28c4b03a9
@ -2412,13 +2412,13 @@ SET @saved_cs_client = @@character_set_client;
|
||||
SET character_set_client = utf8;
|
||||
CREATE TABLE `llx_element_element` (
|
||||
`rowid` int(11) NOT NULL auto_increment,
|
||||
`sourceid` int(11) NOT NULL default '0',
|
||||
`fk_source` int(11) NOT NULL default '0',
|
||||
`sourcetype` varchar(16) NOT NULL default '',
|
||||
`targetid` int(11) NOT NULL default '0',
|
||||
`fk_target` int(11) NOT NULL default '0',
|
||||
`targettype` varchar(16) NOT NULL default '',
|
||||
PRIMARY KEY (`rowid`),
|
||||
UNIQUE KEY `idx_element_element_idx1` (`sourceid`,`sourcetype`,`targetid`,`targettype`),
|
||||
KEY `idx_element_element_targetid` (`targetid`)
|
||||
UNIQUE KEY `idx_element_element_idx1` (`fk_source`,`sourcetype`,`fk_target`,`targettype`),
|
||||
KEY `idx_element_element_fk_target` (`fk_target`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
SET character_set_client = @saved_cs_client;
|
||||
|
||||
|
||||
Binary file not shown.
@ -832,6 +832,19 @@ class CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add objects linked in llx_element_element.
|
||||
*/
|
||||
function add_object_linked($sourceid,$sourcetype,$targetid,$targettype)
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
|
||||
$sql.= "fk_source";
|
||||
$sql.= ", sourcetype";
|
||||
$sql.= ", fk_target";
|
||||
$sql.= ", targettype";
|
||||
$sql.= ") VALUES (";
|
||||
}
|
||||
|
||||
/**
|
||||
* Load array of objects linked to current object. Links are loaded into this->linked_object array.
|
||||
@ -841,10 +854,11 @@ class CommonObject
|
||||
$this->linked_object=array();
|
||||
|
||||
// Links beetween objects are stored in this table
|
||||
$sql = 'SELECT sourceid, sourcetype, targetid, targettype';
|
||||
$sql = 'SELECT fk_source, sourcetype, fk_target, targettype';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'element_element';
|
||||
$sql.= " WHERE (sourceid = '".$this->id."' AND sourcetype = 'invoice')";
|
||||
$sql.= " OR (targetid = '".$this->id."' AND targettype = 'invoice')";
|
||||
$sql.= " WHERE (fk_source = '".$this->id."' AND sourcetype = 'invoice')";
|
||||
$sql.= " OR (fk_target = '".$this->id."' AND targettype = 'invoice')";
|
||||
|
||||
dol_syslog("CommonObject::load_object_linked sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
@ -854,13 +868,13 @@ class CommonObject
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($obj->sourceid == $this->id)
|
||||
if ($obj->fk_source == $this->id)
|
||||
{
|
||||
$this->linked_object[]=array('linkid'=>$obj->targetid, 'type'=>$obj->targettype);
|
||||
$this->linked_object[]=array('linkid'=>$obj->fk_target, 'type'=>$obj->targettype);
|
||||
}
|
||||
if ($obj->targetid == $this->id)
|
||||
if ($obj->fk_target == $this->id)
|
||||
{
|
||||
$this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>$obj->sourcetype);
|
||||
$this->linked_object[]=array('linkid'=>$obj->fk_source, 'type'=>$obj->sourcetype);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
@ -14,3 +14,10 @@ ALTER TABLE llx_stock_mouvement ADD COLUMN label varchar(128);
|
||||
|
||||
ALTER TABLE llx_deplacement ADD COLUMN ref varchar(30) DEFAULT NULL AFTER rowid;
|
||||
ALTER TABLE llx_deplacement ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER ref;
|
||||
|
||||
ALTER TABLE llx_element_element DROP INDEX idx_element_element_idx1;
|
||||
ALTER TABLE llx_element_element DROP INDEX idx_element_element_targetid;
|
||||
ALTER TABLE llx_element_element CHANGE sourceid fk_source integer NOT NULL;
|
||||
ALTER TABLE llx_element_element CHANGE targetid fk_target integer NOT NULL;
|
||||
ALTER TABLE llx_element_element ADD UNIQUE INDEX idx_element_element_idx1 (fk_source, sourcetype, fk_target, targettype);
|
||||
ALTER TABLE llx_element_element ADD INDEX idx_element_element_fk_target (fk_target);
|
||||
|
||||
@ -19,10 +19,10 @@
|
||||
-- ============================================================================
|
||||
|
||||
|
||||
ALTER TABLE llx_element_element ADD UNIQUE INDEX idx_element_element_idx1 (sourceid, sourcetype, targetid, targettype);
|
||||
ALTER TABLE llx_element_element ADD UNIQUE INDEX idx_element_element_idx1 (fk_source, sourcetype, fk_target, targettype);
|
||||
|
||||
|
||||
ALTER TABLE llx_element_element ADD INDEX idx_element_element_targetid (targetid);
|
||||
ALTER TABLE llx_element_element ADD INDEX idx_element_element_fk_target (fk_target);
|
||||
|
||||
-- Pas de contraite sur sourceid et targetid car pointe sur differentes tables
|
||||
-- Pas de contraite sur fk_source et fk_target car pointe sur differentes tables
|
||||
|
||||
@ -24,9 +24,9 @@
|
||||
create table llx_element_element
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
sourceid integer NOT NULL,
|
||||
fk_source integer NOT NULL,
|
||||
sourcetype varchar(16) NOT NULL,
|
||||
targetid integer NOT NULL,
|
||||
fk_target integer NOT NULL,
|
||||
targettype varchar(16) NOT NULL
|
||||
) type=innodb;
|
||||
|
||||
|
||||
@ -388,7 +388,7 @@ class Livraison extends CommonObject
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
// Si module stock g<EFBFBD>r<EFBFBD> et que expedition faite depuis un entrepot
|
||||
// Si module stock gere et que expedition faite depuis un entrepot
|
||||
if (!$conf->expedition->enabled && $conf->stock->enabled && $this->entrepot_id && $conf->global->STOCK_CALCULATE_ON_SHIPMENT == 1)
|
||||
{
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user