Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
bd79e1c1
Commit
bd79e1c1
authored
Nov 18, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sphinx Active Record saving via 'replace' converted into fallback
parent
cd3950aa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
ActiveRecord.php
extensions/sphinx/ActiveRecord.php
+13
-0
ActiveRecordTest.php
tests/unit/extensions/sphinx/ActiveRecordTest.php
+10
-0
No files found.
extensions/sphinx/ActiveRecord.php
View file @
bd79e1c1
...
@@ -851,7 +851,20 @@ class ActiveRecord extends Model
...
@@ -851,7 +851,20 @@ class ActiveRecord extends Model
return
0
;
return
0
;
}
}
// Replace is supported only by runtime indexes and necessary only for field update
$useReplace
=
false
;
$indexSchema
=
$this
->
getIndexSchema
();
if
(
$this
->
getIndexSchema
()
->
isRuntime
)
{
if
(
$this
->
getIndexSchema
()
->
isRuntime
)
{
foreach
(
$values
as
$name
=>
$value
)
{
$columnSchema
=
$indexSchema
->
getColumn
(
$name
);
if
(
$columnSchema
->
isField
)
{
$useReplace
=
true
;
break
;
}
}
}
if
(
$useReplace
)
{
$values
=
array_merge
(
$values
,
$this
->
getOldPrimaryKey
(
true
));
$values
=
array_merge
(
$values
,
$this
->
getOldPrimaryKey
(
true
));
$command
=
static
::
getDb
()
->
createCommand
();
$command
=
static
::
getDb
()
->
createCommand
();
$command
->
replace
(
static
::
indexName
(),
$values
);
$command
->
replace
(
static
::
indexName
(),
$values
);
...
...
tests/unit/extensions/sphinx/ActiveRecordTest.php
View file @
bd79e1c1
...
@@ -161,6 +161,16 @@ class ActiveRecordTest extends SphinxTestCase
...
@@ -161,6 +161,16 @@ class ActiveRecordTest extends SphinxTestCase
$record2
=
RuntimeIndex
::
find
([
'id'
=>
2
]);
$record2
=
RuntimeIndex
::
find
([
'id'
=>
2
]);
$this
->
assertEquals
(
9
,
$record2
->
type_id
);
$this
->
assertEquals
(
9
,
$record2
->
type_id
);
// replace
$query
=
'replace'
;
$rows
=
RuntimeIndex
::
find
(
$query
);
$this
->
assertEmpty
(
$rows
);
$record
=
RuntimeIndex
::
find
([
'id'
=>
2
]);
$record
->
content
=
'Test content with '
.
$query
;
$record
->
save
();
$rows
=
RuntimeIndex
::
find
(
$query
);
$this
->
assertNotEmpty
(
$rows
);
// updateAll
// updateAll
$pk
=
[
'id'
=>
2
];
$pk
=
[
'id'
=>
2
];
$ret
=
RuntimeIndex
::
updateAll
([
'type_id'
=>
55
],
$pk
);
$ret
=
RuntimeIndex
::
updateAll
([
'type_id'
=>
55
],
$pk
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment