|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ubiquity\orm\traits; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Adds transactions in DAO class. |
|
7
|
|
|
* Ubiquity\orm\traits$DAOTransactionsTrait |
|
8
|
|
|
* This class is part of Ubiquity |
|
9
|
|
|
* |
|
10
|
|
|
* @author jcheron <[email protected]> |
|
11
|
|
|
* @version 1.0.0 |
|
12
|
|
|
* @property \Ubiquity\db\Database $db |
|
13
|
|
|
* |
|
14
|
|
|
*/ |
|
15
|
|
|
trait DAOTransactionsTrait { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Initiates a transaction |
|
19
|
|
|
* |
|
20
|
|
|
* @return boolean true on success or false on failure |
|
21
|
|
|
*/ |
|
22
|
|
|
public static function beginTransaction() { |
|
23
|
|
|
return self::$db->beginTransaction (); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Commits a transaction |
|
28
|
|
|
* |
|
29
|
|
|
* @return boolean true on success or false on failure |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function commit() { |
|
32
|
|
|
return self::$db->commit (); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Commits nested transactions up to level $transactionLevel |
|
37
|
|
|
* |
|
38
|
|
|
* @param int $transactionLevel |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function commitToLevel($transactionLevel) { |
|
41
|
|
|
return self::$db->commitToLevel ( $transactionLevel ); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Commits all nested transactions (up to level 0) |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function commitAll() { |
|
48
|
|
|
return self::$db->commitAll (); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Rolls back a transaction |
|
53
|
|
|
* |
|
54
|
|
|
* @return boolean true on success or false on failure |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function rollBack() { |
|
57
|
|
|
return self::$db->rollBack (); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Rolls back nested transactions up to level $transactionLevel |
|
62
|
|
|
* |
|
63
|
|
|
* @param int $transactionLevel |
|
64
|
|
|
*/ |
|
65
|
|
|
public static function rollBackToLevel($transactionLevel) { |
|
66
|
|
|
return self::$db->rollBackToLevel ( $transactionLevel ); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Rolls back all nested transactions (up to level 0) |
|
71
|
|
|
*/ |
|
72
|
|
|
public static function rollBackAll() { |
|
73
|
|
|
return self::$db->rollBackAll (); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Call a callback with an array of parameters in a transaction |
|
78
|
|
|
* |
|
79
|
|
|
* @param callable $callback |
|
80
|
|
|
* @param mixed ...$parameters |
|
81
|
|
|
* @throws \Exception |
|
82
|
|
|
* @return mixed |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function callInTransaction($callback, ...$parameters) { |
|
85
|
|
|
return self::$db->callInTransaction ( $callback, ...$parameters ); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.