Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
816e317d
Commit
816e317d
authored
12 years ago
by
Laurent Destailleur
Browse files
Options
Downloads
Patches
Plain Diff
Fix into categorie functions
parent
e53ae6ee
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
htdocs/categories/class/categorie.class.php
+8
-6
8 additions, 6 deletions
htdocs/categories/class/categorie.class.php
test/phpunit/CategorieTest.php
+9
-1
9 additions, 1 deletion
test/phpunit/CategorieTest.php
with
17 additions
and
7 deletions
htdocs/categories/class/categorie.class.php
+
8
−
6
View file @
816e317d
...
...
@@ -139,11 +139,13 @@ class Categorie
{
$this
->
error
=
$langs
->
trans
(
"ImpossibleAddCat"
);
$this
->
error
.
=
" : "
.
$langs
->
trans
(
"CategoryExistsAtSameLevel"
);
dol_syslog
(
$this
->
error
,
LOG_ERR
);
return
-
4
;
}
$this
->
db
->
begin
();
dol_syslog
(
get_class
(
$this
)
.
'::create sql='
.
$sql
);
$sql
=
"INSERT INTO "
.
MAIN_DB_PREFIX
.
"categorie (label, description,"
;
if
(
$conf
->
global
->
CATEGORY_ASSIGNED_TO_A_CUSTOMER
)
{
...
...
@@ -163,6 +165,7 @@ class Categorie
//$sql.= ",".$this->parentId;
$sql
.
=
")"
;
dol_syslog
(
get_class
(
$this
)
.
'::create sql='
.
$sql
);
$res
=
$this
->
db
->
query
(
$sql
);
if
(
$res
)
{
...
...
@@ -867,6 +870,8 @@ class Categorie
/**
* Check if no category with same label already exists for this cat's parent or root and for this cat's type
* TODO For the moment, the unique key is on the type, label, entity. We must remove table llx_categorie_association
* to replace with a field fk_parent. This will allow to extend unique key with the level.
*
* @return boolean 1 if already exist, 0 otherwise, -1 if error
*/
...
...
@@ -887,17 +892,14 @@ class Categorie
}
else
// mother_id undefined (so it's root)
{
/* We have to select any rowid from llx_categorie which which category's type and label
* are equals to those of the calling category, AND which doesn't exist in categorie association
* as children (rowid != fk_categorie_fille)
/* We have to select any rowid from llx_categorie that is not at root level
*/
$sql
=
"SELECT c.rowid"
;
$sql
.
=
" FROM "
.
MAIN_DB_PREFIX
.
"categorie as c "
;
$sql
.
=
" JOIN "
.
MAIN_DB_PREFIX
.
"categorie_association as ca"
;
$sql
.
=
" ON c.rowid!=ca.fk_categorie_fille"
;
$sql
.
=
" WHERE c.type="
.
$this
->
type
;
$sql
.
=
" AND c.label='"
.
$this
->
db
->
escape
(
$this
->
label
)
.
"'"
;
$sql
.
=
" AND c.entity IN ("
.
getEntity
(
'category'
,
1
)
.
")"
;
$sql
.
=
" AND c.rowid NOT IN (SELECT ca.fk_categorie_fille FROM "
.
MAIN_DB_PREFIX
.
"categorie_association as ca)"
;
}
dol_syslog
(
get_class
(
$this
)
.
"::already_exists sql="
.
$sql
,
LOG_DEBUG
);
$resql
=
$this
->
db
->
query
(
$sql
);
...
...
This diff is collapsed.
Click to expand it.
test/phpunit/CategorieTest.php
+
9
−
1
View file @
816e317d
...
...
@@ -131,6 +131,13 @@ class CategorieTest extends PHPUnit_Framework_TestCase
// We create a category
$localobject
=
new
Categorie
(
$this
->
savdb
);
$localobject
->
initAsSpecimen
();
// Check it does not exist (return 0)
$resultCheck
=
$localobject
->
already_exists
();
print
__METHOD__
.
" resultCheck="
.
$resultCheck
.
"
\n
"
;
$this
->
assertEquals
(
0
,
$resultCheck
);
// Create
$resultFirstCreate
=
$localobject
->
create
(
$user
);
print
__METHOD__
.
" resultFirstCreate="
.
$resultFirstCreate
.
"
\n
"
;
$this
->
assertGreaterThan
(
0
,
$resultFirstCreate
);
...
...
@@ -139,6 +146,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase
$localobject2
=
new
Categorie
(
$this
->
savdb
);
$localobject2
->
initAsSpecimen
();
// Check it does exist (return 1)
$resultCheck
=
$localobject2
->
already_exists
();
print
__METHOD__
.
" resultCheck="
.
$resultCheck
.
"
\n
"
;
$this
->
assertGreaterThan
(
0
,
$resultCheck
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment