Skip to content

Commit decd830

Browse files
committed
Upgraded to Query API
1 parent 5c0bccb commit decd830

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"php" : ">=7.0.0",
1515
"technicalguru/vault" : "^1",
1616
"technicalguru/utils" : "^1",
17-
"technicalguru/database" : "~1.2",
17+
"technicalguru/database" : "~1.3",
1818
"technicalguru/i18n" : "^1",
1919
"technicalguru/rest-client" : "^1",
2020
"technicalguru/email" : "^1",

src/WebApp/DataModel/LogDAO.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace WebApp\DataModel;
44

55
use TgUtils\Date;
6+
use TgDatabase\Restrictions;
67
use WebApp\WebAppException;
78

89
class LogDAO extends \TgDatabase\DAO {
@@ -29,14 +30,12 @@ public function createTable() {
2930
}
3031

3132
public function deleteAll() {
32-
$sql = 'DELETE FROM '.$this->database->quoteName($this->tableName);
33-
$this->database->query($sql);
33+
return $this->createQuery()->delete();
3434
}
3535

3636
public function housekeeping($days = 30) {
37-
$this->threshold = new Date(time()-$days*Date::SECONDS_PER_DAY, WFW_TIMEZONE);
38-
$sql = 'DELETE FROM '.$this->database->quoteName($this->tableName).' WHERE log_date < '.$this->database->prepareValue($threshold);
39-
$this->database->query($sql);
37+
$threshold = new Date(time()-$days*Date::SECONDS_PER_DAY, WFW_TIMEZONE);
38+
$this->createQuery(NULL, Restrictions::lt('log_date', $threshold))->delete();
4039
}
4140
}
4241

src/WebApp/DataModel/SessionDAO.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace WebApp\DataModel;
44

55
use TgUtils\Date;
6+
use TgDatabase\Restrictions;
67
use WebApp\WebAppException;
78

89
/** DataModel class for sessions */
@@ -41,7 +42,9 @@ public function create($object) {
4142

4243
public function expire($maxlifetime) {
4344
$now = new Date(time(), WFW_TIMEZONE);
44-
$expiry = $now->toMysql(TRUE);
45-
$this->deleteBy(array(array('expiry_time', $expiry, '<'), array('persistent', 0)));
45+
$this->createQuery(NULL, array(
46+
Restrictions::lt('expiry_time', $now),
47+
Restrictions::eq('persistent', 0),
48+
))->delete();
4649
}
4750
}

src/WebApp/DataModel/UserDAO.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,22 @@ public function createTable() {
4747
}
4848

4949
public function getByEmail($email) {
50-
return $this->findSingle(array('email' => trim(strtolower($email)), array('status', User::STATUS_DELETED, '!=')));
50+
return $this->findSingle(
51+
array(
52+
Restrictions::eq('email', $email)->ignoreCase(),
53+
Restrictions::ne('status', User::STATUS_DELETED)
54+
)
55+
);
5156
}
5257

5358
public function findByRole($role) {
5459
$rc = array();
55-
$users = $this->find(array('status' => 'active', array('roles', '%'.$role.'%', 'LIKE')));
60+
$users = $this->find(
61+
array(
62+
Restrictions::eq('status', 'active'),
63+
Restrictions::like('roles', '%'.$role.'%')
64+
)
65+
);
5666
foreach ($users AS $user) {
5767
if ($user->hasRole($role)) {
5868
$rc[] = $user;
@@ -75,7 +85,7 @@ public function getSearchInRestriction($s, $property) {
7585
$r->add(Restrictions::like('email', '%'.$s.'%')->ignoreCase());
7686
}
7787
}
78-
$users = $this->createCriteria()->add($r)->add(Restrictions::ne('status', User::STATUS_DELETED))->list();
88+
$users = $this->createQuery(NULL, $r)->add(Restrictions::ne('status', User::STATUS_DELETED))->list();
7989
$uids = \TgUtils\Utils::extractAttributeFromList($users, 'uid');
8090
if (count($uids) == 0) $uids[] = -1;
8191
return Restrictions::in($property, $uids);

0 commit comments

Comments
 (0)