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
37862b6e
Commit
37862b6e
authored
Nov 15, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unsupported "update counters" feature removed from Sphinx Active Record.
parent
d6c38829
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
81 deletions
+0
-81
ActiveRecord.php
extensions/sphinx/ActiveRecord.php
+0
-58
ActiveRecordTest.php
tests/unit/extensions/sphinx/ActiveRecordTest.php
+0
-23
No files found.
extensions/sphinx/ActiveRecord.php
View file @
37862b6e
...
...
@@ -177,34 +177,6 @@ class ActiveRecord extends Model
}
/**
* Updates the whole table using the provided counter changes and conditions.
* For example, to increment all customers' age by 1,
*
* ~~~
* Customer::updateAllCounters(['age' => 1]);
* ~~~
*
* @param array $counters the counters to be updated (attribute name => increment value).
* Use negative values if you want to decrement the counters.
* @param string|array $condition the conditions that will be put in the WHERE part of the UPDATE SQL.
* Please refer to [[Query::where()]] on how to specify this parameter.
* @param array $params the parameters (name => value) to be bound to the query.
* Do not name the parameters as `:bp0`, `:bp1`, etc., because they are used internally by this method.
* @return integer the number of rows updated
*/
public
static
function
updateAllCounters
(
$counters
,
$condition
=
''
,
$params
=
[])
{
$n
=
0
;
foreach
(
$counters
as
$name
=>
$value
)
{
$counters
[
$name
]
=
new
Expression
(
"[[
$name
]]+:bp
{
$n
}
"
,
[
":bp
{
$n
}
"
=>
$value
]);
$n
++
;
}
$command
=
static
::
getDb
()
->
createCommand
();
$command
->
update
(
static
::
indexName
(),
$counters
,
$condition
,
$params
);
return
$command
->
execute
();
}
/**
* Deletes rows in the table using the provided conditions.
* WARNING: If you do not specify any condition, this method will delete ALL rows in the table.
*
...
...
@@ -813,36 +785,6 @@ class ActiveRecord extends Model
}
/**
* Updates one or several counter columns for the current AR object.
* Note that this method differs from [[updateAllCounters()]] in that it only
* saves counters for the current AR object.
*
* An example usage is as follows:
*
* ~~~
* $post = Post::find($id);
* $post->updateCounters(['view_count' => 1]);
* ~~~
*
* @param array $counters the counters to be updated (attribute name => increment value)
* Use negative values if you want to decrement the counters.
* @return boolean whether the saving is successful
* @see updateAllCounters()
*/
public
function
updateCounters
(
$counters
)
{
if
(
$this
->
updateAllCounters
(
$counters
,
$this
->
getOldPrimaryKey
(
true
))
>
0
)
{
foreach
(
$counters
as
$name
=>
$value
)
{
$this
->
_attributes
[
$name
]
+=
$value
;
$this
->
_oldAttributes
[
$name
]
=
$this
->
_attributes
[
$name
];
}
return
true
;
}
else
{
return
false
;
}
}
/**
* Deletes the table row corresponding to this active record.
*
* This method performs the following steps in order:
...
...
tests/unit/extensions/sphinx/ActiveRecordTest.php
View file @
37862b6e
...
...
@@ -161,35 +161,12 @@ class ActiveRecordTest extends SphinxTestCase
$record2
=
RuntimeIndex
::
find
([
'id'
=>
2
]);
$this
->
assertEquals
(
9
,
$record2
->
type_id
);
// updateCounters
/*$pk = ['id' => 1];
$record = RuntimeIndex::find($pk);
$this->assertEquals(1, $record->quantity);
$ret = $record->updateCounters(['quantity' => -1]);
$this->assertTrue($ret);
$this->assertEquals(0, $record->quantity);
$record = RuntimeIndex::find($pk);
$this->assertEquals(0, $record->quantity);*/
// updateAll
$pk
=
[
'id'
=>
2
];
$ret
=
RuntimeIndex
::
updateAll
([
'type_id'
=>
55
],
$pk
);
$this
->
assertEquals
(
1
,
$ret
);
$record
=
RuntimeIndex
::
find
(
$pk
);
$this
->
assertEquals
(
55
,
$record
->
type_id
);
// updateAllCounters
/*$pk = ['order_id' => 1, 'item_id' => 2];
$record = RuntimeIndex::find($pk);
$this->assertEquals(2, $record->quantity);
$ret = RuntimeIndex::updateAllCounters([
'quantity' => 3,
'subtotal' => -10,
], $pk);
$this->assertEquals(1, $ret);
$record = RuntimeIndex::find($pk);
$this->assertEquals(5, $record->quantity);
$this->assertEquals(30, $record->subtotal);*/
}
/**
...
...
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