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
3e75c117
Commit
3e75c117
authored
Sep 24, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup and reorder methods in redis ar + added link+unlink
parent
28c7acc4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
209 additions
and
259 deletions
+209
-259
ActiveQuery.php
framework/yii/redis/ActiveQuery.php
+1
-4
ActiveRecord.php
framework/yii/redis/ActiveRecord.php
+168
-126
ActiveRelation.php
framework/yii/redis/ActiveRelation.php
+15
-6
Connection.php
framework/yii/redis/Connection.php
+1
-3
RecordSchema.php
framework/yii/redis/RecordSchema.php
+3
-4
Transaction.php
framework/yii/redis/Transaction.php
+0
-93
ActiveRecordTest.php
tests/unit/framework/redis/ActiveRecordTest.php
+21
-23
No files found.
framework/yii/redis/ActiveQuery.php
View file @
3e75c117
<?php
/**
* ActiveRecord class file.
*
* @author Carsten Brandt <mail@cebe.cc>
* @link http://www.yiiframework.com/
* @copyright Copyright
©
2008 Yii Software LLC
* @copyright Copyright
(c)
2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
...
...
framework/yii/redis/ActiveRecord.php
View file @
3e75c117
This diff is collapsed.
Click to expand it.
framework/yii/redis/ActiveRelation.php
View file @
3e75c117
<?php
/**
* ActiveRecord class file.
*
* @author Carsten Brandt <mail@cebe.cc>
* @link http://www.yiiframework.com/
* @copyright Copyright
©
2008 Yii Software LLC
* @copyright Copyright
(c)
2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\redis
;
use
yii\base\InvalidConfigException
;
// TODO this class is nearly completely duplicated from yii\db\ActiveRelation
/**
* ActiveRecord is the base class for classes representing relational data in terms of objects.
* ActiveRelation represents a relation between two Active Record classes.
*
* ActiveRelation instances are usually created by calling [[ActiveRecord::hasOne()]] and
* [[ActiveRecord::hasMany()]]. An Active Record class declares a relation by defining
* a getter method which calls one of the above methods and returns the created ActiveRelation object.
*
* A relation is specified by [[link]] which represents the association between columns
* of different tables; and the multiplicity of the relation is indicated by [[multiple]].
*
* If a relation involves a pivot table, it may be specified by [[via()]] or [[viaTable()]] method.
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class
ActiveRelation
extends
\yii\redis\
ActiveQuery
class
ActiveRelation
extends
ActiveQuery
{
/**
* @var boolean whether this relation should populate all query results into AR instances.
...
...
framework/yii/redis/Connection.php
View file @
3e75c117
<?php
/**
* Connection class file
*
* @link http://www.yiiframework.com/
* @copyright Copyright
©
2008 Yii Software LLC
* @copyright Copyright
(c)
2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
...
...
framework/yii/redis/RecordSchema.php
View file @
3e75c117
<?php
/**
*
*
* @
author Carsten Brandt <mail@cebe.cc>
*
@link http://www.yiiframework.com/
*
@copyright Copyright (c) 2008 Yii Software LLC
* @
license http://www.yiiframework.com/license/
*/
namespace
yii\redis
;
use
yii\base\InvalidConfigException
;
use
yii\db\TableSchema
;
...
...
framework/yii/redis/Transaction.php
deleted
100644 → 0
View file @
28c7acc4
<?php
/**
* Transaction class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\redis
;
use
yii\base\InvalidConfigException
;
use
yii\db\Exception
;
/**
* Transaction represents a DB transaction.
*
* @property boolean $isActive Whether this transaction is active. Only an active transaction can [[commit()]]
* or [[rollBack()]]. This property is read-only.
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class
Transaction
extends
\yii\base\Object
{
/**
* @var Connection the database connection that this transaction is associated with.
*/
public
$db
;
/**
* @var boolean whether this transaction is active. Only an active transaction
* can [[commit()]] or [[rollBack()]]. This property is set true when the transaction is started.
*/
private
$_active
=
false
;
/**
* Returns a value indicating whether this transaction is active.
* @return boolean whether this transaction is active. Only an active transaction
* can [[commit()]] or [[rollBack()]].
*/
public
function
getIsActive
()
{
return
$this
->
_active
;
}
/**
* Begins a transaction.
* @throws InvalidConfigException if [[connection]] is null
*/
public
function
begin
()
{
if
(
!
$this
->
_active
)
{
if
(
$this
->
db
===
null
)
{
throw
new
InvalidConfigException
(
'Transaction::db must be set.'
);
}
\Yii
::
trace
(
'Starting transaction'
,
__CLASS__
);
$this
->
db
->
open
();
$this
->
db
->
createCommand
(
'MULTI'
)
->
execute
();
$this
->
_active
=
true
;
}
}
/**
* Commits a transaction.
* @throws Exception if the transaction or the DB connection is not active.
*/
public
function
commit
()
{
if
(
$this
->
_active
&&
$this
->
db
&&
$this
->
db
->
isActive
)
{
\Yii
::
trace
(
'Committing transaction'
,
__CLASS__
);
$this
->
db
->
createCommand
(
'EXEC'
)
->
execute
();
// TODO handle result of EXEC
$this
->
_active
=
false
;
}
else
{
throw
new
Exception
(
'Failed to commit transaction: transaction was inactive.'
);
}
}
/**
* Rolls back a transaction.
* @throws Exception if the transaction or the DB connection is not active.
*/
public
function
rollback
()
{
if
(
$this
->
_active
&&
$this
->
db
&&
$this
->
db
->
isActive
)
{
\Yii
::
trace
(
'Rolling back transaction'
,
__CLASS__
);
$this
->
db
->
pdo
->
commit
();
$this
->
_active
=
false
;
}
else
{
throw
new
Exception
(
'Failed to roll back transaction: transaction was inactive.'
);
}
}
}
tests/unit/framework/redis/ActiveRecordTest.php
View file @
3e75c117
...
...
@@ -319,21 +319,20 @@ class ActiveRecordTest extends RedisTestCase
$this
->
assertEquals
(
1
,
$order
->
customer_id
);
$this
->
assertEquals
(
1
,
$order
->
customer
->
id
);
// TODO support via
// // via model
// $order = Order::find(1);
// $this->assertEquals(2, count($order->items));
// $this->assertEquals(2, count($order->orderItems));
// $orderItem = OrderItem::find(array('order_id' => 1, 'item_id' => 3));
// $this->assertNull($orderItem);
// $item = Item::find(3);
// $order->link('items', $item, array('quantity' => 10, 'subtotal' => 100));
// $this->assertEquals(3, count($order->items));
// $this->assertEquals(3, count($order->orderItems));
// $orderItem = OrderItem::find(array('order_id' => 1, 'item_id' => 3));
// $this->assertTrue($orderItem instanceof OrderItem);
// $this->assertEquals(10, $orderItem->quantity);
// $this->assertEquals(100, $orderItem->subtotal);
// via model
$order
=
Order
::
find
(
1
);
$this
->
assertEquals
(
2
,
count
(
$order
->
items
));
$this
->
assertEquals
(
2
,
count
(
$order
->
orderItems
));
$orderItem
=
OrderItem
::
find
(
array
(
'order_id'
=>
1
,
'item_id'
=>
3
));
$this
->
assertNull
(
$orderItem
);
$item
=
Item
::
find
(
3
);
$order
->
link
(
'items'
,
$item
,
array
(
'quantity'
=>
10
,
'subtotal'
=>
100
));
$this
->
assertEquals
(
3
,
count
(
$order
->
items
));
$this
->
assertEquals
(
3
,
count
(
$order
->
orderItems
));
$orderItem
=
OrderItem
::
find
(
array
(
'order_id'
=>
1
,
'item_id'
=>
3
));
$this
->
assertTrue
(
$orderItem
instanceof
OrderItem
);
$this
->
assertEquals
(
10
,
$orderItem
->
quantity
);
$this
->
assertEquals
(
100
,
$orderItem
->
subtotal
);
}
public
function
testUnlink
()
...
...
@@ -345,14 +344,13 @@ class ActiveRecordTest extends RedisTestCase
$this
->
assertEquals
(
1
,
count
(
$customer
->
orders
));
$this
->
assertNull
(
Order
::
find
(
3
));
// TODO support via
// // via model
// $order = Order::find(2);
// $this->assertEquals(3, count($order->items));
// $this->assertEquals(3, count($order->orderItems));
// $order->unlink('items', $order->items[2], true);
// $this->assertEquals(2, count($order->items));
// $this->assertEquals(2, count($order->orderItems));
// via model
$order
=
Order
::
find
(
2
);
$this
->
assertEquals
(
3
,
count
(
$order
->
items
));
$this
->
assertEquals
(
3
,
count
(
$order
->
orderItems
));
$order
->
unlink
(
'items'
,
$order
->
items
[
2
],
true
);
$this
->
assertEquals
(
2
,
count
(
$order
->
items
));
$this
->
assertEquals
(
2
,
count
(
$order
->
orderItems
));
}
public
function
testInsert
()
...
...
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