Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#6264 Remove adodb #6318

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
965f74b
pkp/pkp-lib#6264 Introduce upsert Laravel extension; make DAOResultFa…
asmecher Oct 2, 2020
cee149d
pkp/pkp-lib#6264 Remove ADODB
asmecher Oct 2, 2020
1d605b1
pkp/pkp-lib#6264 DAO adaptations
asmecher Oct 2, 2020
08f8381
pkp/pkp-lib#6264 DAO adaptations
asmecher Oct 6, 2020
706910d
pkp/pkp-lib#6264 DAO adaptations
asmecher Oct 6, 2020
182b76c
pkp/pkp-lib#6264 Move ADODB to development requirement (for schema co…
asmecher Oct 6, 2020
58b4529
pkp/pkp-lib#6264 DAO adaptations
asmecher Oct 9, 2020
94dc0e5
pkp/pkp-lib#6264 Try rewrite of DAOResultFactory etc. to avoid genera…
asmecher Oct 9, 2020
e1477b3
pkp/pkp-lib#6264 Upgrade Laravel database libraries (required?)
asmecher Oct 9, 2020
c47ae0f
pkp/pkp-lib#6264 DAO adaptations
asmecher Oct 9, 2020
f5f7eea
pkp/pkp-lib#6264 Prevent counting of iterated result sets
asmecher Oct 13, 2020
2725ff3
pkp/pkp-lib#6264 Convert assertions to exceptions
asmecher Oct 14, 2020
eceee3e
pkp/pkp-lib#6264 Remove unused functionParams; array syntax
asmecher Oct 14, 2020
727c681
pkp/pkp-lib#6264 Array syntax
asmecher Oct 14, 2020
ba12faa
pkp/pkp-lib#6264 DAO adaptations
asmecher Oct 14, 2020
feca5aa
pkp/pkp-lib#6264 Clean up count work-around syntax
asmecher Oct 14, 2020
f8b7d81
pkp/pkp-lib#6264 Fix NULL date formatting for DB; paging needs to be …
asmecher Oct 14, 2020
7f1b886
pkp/pkp-lib#6264 Shorten DAOResultFactory::toArray
asmecher Oct 14, 2020
b41b949
pkp/pkp-lib#6264 Enable paging workaround in affected code
asmecher Oct 14, 2020
80b1c57
pkp/pkp-lib#6264 DAO adaptations
asmecher Oct 14, 2020
62b52c9
pkp/pkp-lib#6264 Revert paging to DAO; support paging work-around
asmecher Oct 14, 2020
66ef094
pkp/pkp-lib#6264 DAO adaptations
asmecher Oct 14, 2020
0c78f2c
pkp/pkp-lib#6264 Fix NULL date formatting for DB
asmecher Oct 14, 2020
7a34439
pkp/pkp-lib#6264 Fix date formatting for DB
asmecher Oct 14, 2020
4a2c0a0
pkp/pkp-lib#6264 DAO adaptations
asmecher Oct 14, 2020
786afb5
pkp/pkp-lib#6264 DAO adaptations
asmecher Oct 15, 2020
33f2091
pkp/pkp-lib#6264 DAO adaptations; remove eof and row count calls (no …
asmecher Oct 15, 2020
a9125cb
pkp/pkp-lib#6264 DAO adaptations: Remove calls to nonexistent DAOResu…
asmecher Oct 16, 2020
24c5221
pkp/pkp-lib#6264 DAO adaptations: Remove calls to nonexistent DAOResu…
asmecher Oct 17, 2020
0e554fc
pkp/pkp-lib#6264 Fix tests
asmecher Oct 29, 2020
1c138f2
pkp/pkp-lib#6264 DAO adaptations; fix tests
asmecher Oct 29, 2020
779c1a0
pkp/pkp-lib#6264 Fix tests
asmecher Oct 30, 2020
ef49ebd
Remove URL validator test case (apparently passes Laravel validator)
asmecher Oct 30, 2020
1b37bb6
pkp/pkp-lib#6264 Fix use/count DAO calls
asmecher Nov 5, 2020
bc60f2b
Array syntax
asmecher Nov 5, 2020
404e728
pkp/pkp-lib#6264 Fix upsert problem with PostgreSQL
asmecher Nov 5, 2020
7555681
pkp/pkp-lib#6264 DAO adaptations
asmecher Nov 5, 2020
1662d1e
pkp/pkp-lib#6264 DAO adaptations
asmecher Nov 5, 2020
ca71971
pkp/pkp-lib#6264 Improve array/stdobject syntax
asmecher Nov 6, 2020
767a8ca
pkp/pkp-lib#6264 Remove cached DB retrieval
asmecher Nov 6, 2020
1cb47e3
Improve self-documentation
asmecher Nov 6, 2020
9b06e50
pkp/pkp-lib#6264 Remove cached DB retrieval
asmecher Nov 6, 2020
5601288
pkp/pkp-lib#6264 Introduce Generators to normal use cases instead of …
asmecher Nov 6, 2020
76fb957
pkp/pkp-lib#6264 Improve self-documentation
asmecher Nov 10, 2020
3b70560
pkp/pkp-lib#6264 DAO adaptations
asmecher Nov 10, 2020
1103f2e
pkp/pkp-lib#6264 Fix old XML-based schema alteration tools for legacy…
asmecher Nov 10, 2020
a8f5b96
pkp/pkp-lib#6264 Array syntax
asmecher Nov 10, 2020
694b61a
pkp/pkp-lib#6264 Paging fix
asmecher Nov 10, 2020
0271262
pkp/pkp-lib#6264 Array syntax
asmecher Nov 10, 2020
0b87fce
pkp/pkp-lib#6264 Correct self-documentation
asmecher Nov 10, 2020
64b8f0d
Array syntax; use exceptions instead of fatalError
asmecher Nov 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions api/v1/stats/publications/PKPStatsPublicationHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,11 @@ public function getMany($slimRequest, $response, $args) {
$statsQB->filterBySubmissions($allowedParams['submissionIds']);
}
$statsQO = $statsQB->getSubmissionIds();
$result = \DAORegistry::getDAO('MetricsDAO')
->retrieve($statsQO->toSql(), $statsQO->getBindings());
$itemsMax = $result->RecordCount();

$metricsDao = \DAORegistry::getDAO('MetricsDAO'); /** @var MetricsDAO */
return $response->withJson([
'items' => $items,
'itemsMax' => $itemsMax,
'itemsMax' => $metricsDao->countRecords($statsQO->toSql(), $statsQO->getBindings()),
], 200);
}

Expand Down
40 changes: 16 additions & 24 deletions api/v1/users/PKPUserHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,18 @@ public function getMany($slimRequest, $response, $args) {

$items = [];
$usersItereator = Services::get('user')->getMany($params);
if (count($usersItereator)) {
$propertyArgs = [
'request' => $request,
'slimRequest' => $slimRequest,
];
foreach ($usersItereator as $user) {
$items[] = Services::get('user')->getSummaryProperties($user, $propertyArgs);
}
$propertyArgs = [
'request' => $request,
'slimRequest' => $slimRequest,
];
foreach ($usersItereator as $user) {
$items[] = Services::get('user')->getSummaryProperties($user, $propertyArgs);
}

$data = [
return $response->withJson([
'itemsMax' => Services::get('user')->getMax($params),
'items' => $items,
];

return $response->withJson($data, 200);
], 200);
}

/**
Expand Down Expand Up @@ -174,22 +170,18 @@ public function getReviewers($slimRequest, $response, $args) {

$items = [];
$usersIterator = Services::get('user')->getReviewers($params);
if (count($usersIterator)) {
$propertyArgs = [
'request' => $request,
'slimRequest' => $slimRequest,
];
foreach ($usersIterator as $user) {
$items[] = Services::get('user')->getReviewerSummaryProperties($user, $propertyArgs);
}
$propertyArgs = [
'request' => $request,
'slimRequest' => $slimRequest,
];
foreach ($usersIterator as $user) {
$items[] = Services::get('user')->getReviewerSummaryProperties($user, $propertyArgs);
}

$data = array(
return $response->withJson([
'itemsMax' => Services::get('user')->getReviewersMax($params),
'items' => $items,
);

return $response->withJson($data, 200);
], 200);
}

/**
Expand Down
11 changes: 5 additions & 6 deletions classes/announcement/Announcement.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ function setTypeId($typeId) {

/**
* Get the announcement type name of the announcement.
* @return string
* @return string|null
*/
function getAnnouncementTypeName() {
$announcementTypeDao = DAORegistry::getDAO('AnnouncementTypeDAO'); /* @var $announcementTypeDao AnnouncementTypeDAO */
return $announcementTypeDao->getAnnouncementTypeName($this->getData('typeId'));
$announcementType = $announcementTypeDao->getById($this->getData('typeId'));
return $announcementType ? $announcementType->getLocalizedTypeName() : null;
}

/**
Expand All @@ -95,12 +96,10 @@ function getLocalizedTitle() {
*/
function getLocalizedTitleFull() {
$typeName = $this->getAnnouncementTypeName();
$title = $this->getLocalizedTitle();

if (!empty($typeName)) {
return $typeName . ': ' . $title;
return $typeName . ': ' . $this->getLocalizedTitle();
} else {
return $title;
return $this->getLocalizedTitle();
}
}

Expand Down
106 changes: 31 additions & 75 deletions classes/announcement/AnnouncementDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import('lib.pkp.classes.announcement.Announcement');
import('lib.pkp.classes.db.SchemaDAO');

use Illuminate\Database\Capsule\Manager as Capsule;

class AnnouncementDAO extends SchemaDAO {
/** @var string One of the SCHEMA_... constants */
var $schemaName = SCHEMA_ANNOUNCEMENT;
Expand Down Expand Up @@ -48,50 +50,13 @@ class AnnouncementDAO extends SchemaDAO {
* @return Announcement
*/
function getById($announcementId, $assocType = null, $assocId = null) {
$params = array((int) $announcementId);
if ($assocType !== null) $params[] = (int) $assocType;
if ($assocId !== null) $params[] = (int) $assocId;
$result = $this->retrieve(
'SELECT * FROM announcements WHERE announcement_id = ?' .
($assocType !== null?' AND assoc_type = ?':'') .
($assocId !== null?' AND assoc_id = ?':''),
$params
);

$returner = null;
if ($result->RecordCount() != 0) {
$returner = $this->_fromRow($result->GetRowAssoc(false));
$query = Capsule::table($this->tableName)->where($this->primaryKeyColumn, '=', (int) $announcementId);
if ($assocType !== null) $query->where('assoc_type', '=', (int) $assocType);
if ($assocId !== null) $query->where('assoc_id', '=', (int) $assocType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, does the query builder handle type conversions like this? I've often wondered whether I need to cast to int but never taken the time to experiment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question; I'll test when I have a sec. Using ADODB, PostgreSQL would complain if the data type didn't match the column type; I would expect PDO to behave the same. This could cause SQL failures when binding a user-supplied parameter, if the user entered a string instead of a number. Putting the casts in the binding resulted in more not-foundish behaviour than fatal-errorish.

if ($result = $query->first()) {
return $this->_fromRow((array) $result);
}
$result->Close();
return $returner;
}

/**
* Retrieve announcement Assoc ID by announcement ID.
* @param $announcementId int
* @return int
*/
function getAnnouncementAssocId($announcementId) {
$result = $this->retrieve(
'SELECT assoc_id FROM announcements WHERE announcement_id = ?',
(int) $announcementId
);

return isset($result->fields[0]) ? $result->fields[0] : 0;
}

/**
* Retrieve announcement Assoc ID by announcement ID.
* @param $announcementId int
* @return int
*/
function getAnnouncementAssocType($announcementId) {
$result = $this->retrieve(
'SELECT assoc_type FROM announcements WHERE announcement_id = ?',
(int) $announcementId
);

return isset($result->fields[0]) ? $result->fields[0] : 0;
return null;
}

/**
Expand All @@ -108,8 +73,7 @@ function newDataObject() {
* @return boolean
*/
function deleteByTypeId($typeId) {
$announcements = $this->getByTypeId($typeId);
while ($announcement = $announcements->next()) {
foreach ($this->getByTypeId($typeId) as $announcement) {
$this->deleteObject($announcement);
}
}
Expand All @@ -131,36 +95,33 @@ function deleteByAssoc($assocType, $assocId) {
* Retrieve an array of announcements matching a particular assoc ID.
* @param $assocType int ASSOC_TYPE_...
* @param $assocId int
* @param $rangeInfo DBResultRange (optional)
* @return object DAOResultFactory containing matching Announcements
* @return Generator Matching Announcements
*/
function getByAssocId($assocType, $assocId, $rangeInfo = null) {
$result = $this->retrieveRange(
'SELECT *
FROM announcements
WHERE assoc_type = ? AND assoc_id = ?
ORDER BY date_posted DESC',
array((int) $assocType, (int) $assocId),
$rangeInfo
);

return new DAOResultFactory($result, $this, '_fromRow');
function getByAssocId($assocType, $assocId) {
$result = Capsule::table($this->tableName)
->where('assoc_type', '=', (int) $assocType)
->where('assoc_id', '=', (int) $assocId)
->orderByDesc('date_posted')
->get();
foreach ($result as $row) {
yield $this->_fromRow((array) $row);
}
}

/**
* Retrieve an array of announcements matching a particular type ID.
* @param $typeId int
* @param $rangeInfo DBResultRange (optional)
* @return object DAOResultFactory containing matching Announcements
* @return Generator Matching Announcements
*/
function getByTypeId($typeId, $rangeInfo = null) {
function getByTypeId($typeId) {
$result = $this->retrieveRange(
'SELECT * FROM announcements WHERE type_id = ? ORDER BY date_posted DESC',
(int) $typeId,
[(int) $typeId],
$rangeInfo
);

return new DAOResultFactory($result, $this, '_fromRow');
foreach ($result as $row) {
yield $this->_fromRow((array) $row);
}
}

/**
Expand All @@ -178,7 +139,7 @@ function getNumAnnouncementsByAssocId($assocType, $assocId, $numAnnouncements, $
WHERE assoc_type = ?
AND assoc_id = ?
ORDER BY date_posted DESC LIMIT ?',
array((int) $assocType, (int) $assocId, (int) $numAnnouncements),
[(int) $assocType, (int) $assocId, (int) $numAnnouncements],
$rangeInfo
);

Expand All @@ -201,7 +162,7 @@ function getAnnouncementsNotExpiredByAssocId($assocType, $assocId, $rangeInfo =
AND (date_expire IS NULL OR DATE(date_expire) > DATE(NOW()))
AND (DATE(date_posted) <= DATE(NOW()))
ORDER BY date_posted DESC',
array((int) $assocType, (int) $assocId),
[(int) $assocType, (int) $assocId],
$rangeInfo
);

Expand All @@ -225,7 +186,7 @@ function getNumAnnouncementsNotExpiredByAssocId($assocType, $assocId, $numAnnoun
AND (date_expire IS NULL OR DATE(date_expire) > DATE(NOW()))
AND (DATE(date_posted) <= DATE(NOW()))
ORDER BY date_posted DESC LIMIT ?',
array((int) $assocType, (int) $assocId, (int) $numAnnouncements),
[(int) $assocType, (int) $assocId, (int) $numAnnouncements],
$rangeInfo
);

Expand All @@ -245,15 +206,10 @@ function getMostRecentAnnouncementByAssocId($assocType, $assocId) {
WHERE assoc_type = ?
AND assoc_id = ?
ORDER BY date_posted DESC LIMIT 1',
array((int) $assocType, (int) $assocId)
[(int) $assocType, (int) $assocId]
);

$returner = null;
if ($result->RecordCount() != 0) {
$returner = $this->_fromRow($result->GetRowAssoc(false));
}
$result->Close();
return $returner;
$row = $result->current();
return $row ? $this->_fromRow((array) $row) : null;
}

/**
Expand Down
Loading