Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
7737f090
Commit
7737f090
authored
9 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
search: Plumb up deletes to clear the search index
parent
4d074562
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class.search.php
+37
-14
37 additions, 14 deletions
include/class.search.php
with
37 additions
and
14 deletions
include/class.search.php
+
37
−
14
View file @
7737f090
...
...
@@ -82,16 +82,19 @@ class SearchInterface {
}
function
update
(
$model
,
$id
,
$content
,
$new
=
false
,
$attrs
=
array
())
{
if
(
!
$this
->
backend
)
return
;
$this
->
backend
->
update
(
$model
,
$id
,
$content
,
$new
,
$attrs
);
if
(
$this
->
backend
)
$this
->
backend
->
update
(
$model
,
$id
,
$content
,
$new
,
$attrs
);
}
function
createModel
(
$model
)
{
return
$this
->
updateModel
(
$model
,
true
);
}
function
deleteModel
(
$model
)
{
if
(
$this
->
backend
)
$this
->
backend
->
delete
(
$model
);
}
function
updateModel
(
$model
,
$new
=
false
)
{
// The MySQL backend does not need to index attributes of the
// various models, because those other attributes are available in
...
...
@@ -104,11 +107,10 @@ class SearchInterface {
break
;
$this
->
update
(
$model
,
$model
->
getId
(),
$model
->
getBody
()
->
getSearchable
(),
$new
,
$model
->
getBody
()
->
getSearchable
(),
$new
===
true
,
array
(
'title'
=>
$model
->
getTitle
(),
//TODO: send attribute of object_id
'ticket_id'
=>
$model
->
getThread
()
->
getObjectId
(),
'created'
=>
$model
->
getCreateDate
(),
)
);
...
...
@@ -121,7 +123,7 @@ class SearchInterface {
$cdata
[]
=
$v
;
$this
->
update
(
$model
,
$model
->
getId
(),
trim
(
implode
(
"
\n
"
,
$cdata
)),
$new
,
$new
===
true
,
array
(
'title'
=>
Format
::
searchable
(
$model
->
getSubject
()),
'number'
=>
$model
->
getNumber
(),
...
...
@@ -148,7 +150,7 @@ class SearchInterface {
$cdata
[]
=
$v
;
$this
->
update
(
$model
,
$model
->
getId
(),
trim
(
implode
(
"
\n
"
,
$cdata
)),
$new
,
$new
===
true
,
array
(
'title'
=>
Format
::
searchable
(
$model
->
getFullName
()),
'emails'
=>
$model
->
emails
->
asArray
(),
...
...
@@ -166,7 +168,7 @@ class SearchInterface {
$cdata
[]
=
$v
;
$this
->
update
(
$model
,
$model
->
getId
(),
trim
(
implode
(
"
\n
"
,
$cdata
)),
$new
,
$new
===
true
,
array
(
'title'
=>
Format
::
searchable
(
$model
->
getName
()),
'created'
=>
$model
->
getCreateDate
(),
...
...
@@ -177,7 +179,7 @@ class SearchInterface {
case
$model
instanceof
FAQ
:
$this
->
update
(
$model
,
$model
->
getId
(),
$model
->
getSearchableAnswer
(),
$new
,
$new
===
true
,
array
(
'title'
=>
Format
::
searchable
(
$model
->
getQuestion
()),
'keywords'
=>
$model
->
getKeywords
(),
...
...
@@ -219,7 +221,7 @@ class SearchInterface {
Signal
::
connect
(
'model.created'
,
array
(
$this
,
'createModel'
),
'FAQ'
);
Signal
::
connect
(
'model.updated'
,
array
(
$this
,
'updateModel'
));
#
Signal::connect('model.deleted', array($this, 'deleteModel'));
Signal
::
connect
(
'model.deleted'
,
array
(
$this
,
'deleteModel'
));
}
}
...
...
@@ -239,6 +241,7 @@ class MysqlSearchBackend extends SearchBackend {
// Only index 20 batches per cron run
var
$max_batches
=
60
;
var
$_reindexed
=
0
;
var
$SEARCH_TABLE
;
function
__construct
()
{
$this
->
SEARCH_TABLE
=
TABLE_PREFIX
.
'_search'
;
...
...
@@ -257,8 +260,6 @@ class MysqlSearchBackend extends SearchBackend {
}
function
update
(
$model
,
$id
,
$content
,
$new
=
false
,
$attrs
=
array
())
{
if
(
!
(
$type
=
ObjectModel
::
getType
(
$model
)))
return
;
...
...
@@ -271,6 +272,8 @@ class MysqlSearchBackend extends SearchBackend {
if
(
!
$content
&&
!
$title
)
return
;
if
(
!
$id
)
return
;
$sql
=
'REPLACE INTO '
.
$this
->
SEARCH_TABLE
.
' SET object_type='
.
db_input
(
$type
)
...
...
@@ -280,6 +283,26 @@ class MysqlSearchBackend extends SearchBackend {
return
db_query
(
$sql
);
}
function
delete
(
$model
)
{
switch
(
true
)
{
case
$model
instanceof
Thread
:
$sql
=
'DELETE s.* FROM '
.
$this
->
SEARCH_TABLE
.
" s JOIN "
.
THREAD_ENTRY_TABLE
.
" h ON (h.id = s.object_id) "
.
" WHERE s.object_type='H'"
.
' AND h.thread_id='
.
db_input
(
$model
->
getId
());
return
db_query
(
$sql
);
default
:
if
(
!
(
$type
=
ObjectModel
::
getType
(
$model
)))
return
;
$sql
=
'DELETE FROM '
.
$this
->
SEARCH_TABLE
.
' WHERE object_type='
.
db_input
(
$type
)
.
' AND object_id='
.
db_input
(
$model
->
getId
());
return
db_query
(
$sql
);
}
}
// Quote things like email addresses
function
quote
(
$query
)
{
$parts
=
array
();
...
...
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