mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
Updating queries to be more DB agnostic
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@66506 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
f067bd1304
commit
e79dd5558b
@ -237,7 +237,7 @@ JS
|
||||
$fileNames = array();
|
||||
foreach($newFiles as $newFile) {
|
||||
$fileIDs[] = $newFile;
|
||||
$fileObj = DataObject::get_one('File', "\"File\".ID=$newFile");
|
||||
$fileObj = DataObject::get_one('File', "\"File\".\"ID\"=$newFile");
|
||||
$fileNames[] = $fileObj->Name;
|
||||
}
|
||||
|
||||
@ -314,7 +314,7 @@ HTML;
|
||||
$numFiles = 0;
|
||||
|
||||
if($fileList != "''") {
|
||||
$files = DataObject::get("File", "\"File\".ID IN ($fileList)");
|
||||
$files = DataObject::get("File", "\"File\".\"ID\" IN ($fileList)");
|
||||
if($files) {
|
||||
foreach($files as $file) {
|
||||
if($file instanceof Image) {
|
||||
@ -350,7 +350,7 @@ HTML;
|
||||
$brokenPageList = '';
|
||||
|
||||
if($fileList != "''") {
|
||||
$files = DataObject::get("File", "\"File\".ID IN ($fileList)");
|
||||
$files = DataObject::get("File", "\"File\".\"ID\" IN ($fileList)");
|
||||
if($files) {
|
||||
foreach($files as $file) {
|
||||
if($file instanceof Image) {
|
||||
|
@ -46,7 +46,7 @@ class AssetTableField extends ComplexTableField {
|
||||
function setFolder($folder) {
|
||||
$this->folder = $folder;
|
||||
$this->sourceFilter .= ($this->sourceFilter) ? " AND " : "";
|
||||
$this->sourceFilter .= " ParentID = '" . $folder->ID . "' AND ClassName <> 'Folder'";
|
||||
$this->sourceFilter .= " \"ParentID\" = '" . $folder->ID . "' AND \"ClassName\" <> 'Folder'";
|
||||
}
|
||||
|
||||
function Folder() {
|
||||
|
@ -513,7 +513,7 @@ JS;
|
||||
// DataObject::fieldExists only checks the current class, not the hierarchy
|
||||
// This allows the CMS to set the correct sort value
|
||||
if($newItem->castingHelperPair('Sort')) {
|
||||
$newItem->Sort = DB::query("SELECT MAX(Sort) FROM SiteTree WHERE ParentID = '" . Convert::raw2sql($parentID) . "'")->value() + 1;
|
||||
$newItem->Sort = DB::query("SELECT MAX(\"Sort\") FROM \"SiteTree\" WHERE \"ParentID\" = '" . Convert::raw2sql($parentID) . "'")->value() + 1;
|
||||
}
|
||||
|
||||
if( Member::currentUser() )
|
||||
@ -596,7 +596,7 @@ JS;
|
||||
*/
|
||||
public function delete($urlParams, $form) {
|
||||
$id = $_REQUEST['ID'];
|
||||
$record = DataObject::get_one("SiteTree", "SiteTree.\"ID\" = $id");
|
||||
$record = DataObject::get_one("SiteTree", "\"SiteTree\".\"ID\" = $id");
|
||||
if($record && !$record->canDelete()) return Security::permissionFailure();
|
||||
|
||||
$recordID = $record->ID;
|
||||
@ -662,7 +662,7 @@ JS;
|
||||
if($groupIDs) {
|
||||
$groupList = implode(", ", $groupIDs);
|
||||
$members = DataObject::get("Member","","",
|
||||
"INNER JOIN \"Group_Members\" ON \"Group_Members\".MemberID = \"Member\".ID AND \"Group_Members\".GroupID IN ($groupList)");
|
||||
"INNER JOIN \"Group_Members\" ON \"Group_Members\".\"MemberID\" = \"Member\".\"ID\" AND \"Group_Members\".\"GroupID\" IN ($groupList)");
|
||||
}
|
||||
|
||||
if($members) {
|
||||
@ -687,7 +687,7 @@ HTML;
|
||||
}
|
||||
|
||||
function tasklist() {
|
||||
$tasks = DataObject::get("Page", "AssignedToID = " . Member::currentUserID(), "Created DESC");
|
||||
$tasks = DataObject::get("Page", "\"AssignedToID\" = " . Member::currentUserID(), "\"Created\" DESC");
|
||||
if($tasks) {
|
||||
$data = new ArrayData(array(
|
||||
"Tasks" => $tasks,
|
||||
@ -702,7 +702,7 @@ HTML;
|
||||
}
|
||||
|
||||
function waitingon() {
|
||||
$tasks = DataObject::get("Page", "RequestedByID = " . Member::currentUserID(), "Created DESC");
|
||||
$tasks = DataObject::get("Page", "\"RequestedByID\" = " . Member::currentUserID(), "\"Created\" DESC");
|
||||
if($tasks) {
|
||||
$data = new ArrayData(array(
|
||||
"Tasks" => $tasks,
|
||||
@ -718,7 +718,7 @@ HTML;
|
||||
|
||||
function comments() {
|
||||
if($this->urlParams['ID']) {
|
||||
$comments = DataObject::get("WorkflowPageComment", "PageID = " . $this->urlParams['ID'], "Created DESC");
|
||||
$comments = DataObject::get("WorkflowPageComment", "\"PageID\" = " . $this->urlParams['ID'], "\"Created\" DESC");
|
||||
$data = new ArrayData(array(
|
||||
"Comments" => $comments,
|
||||
));
|
||||
@ -1169,7 +1169,7 @@ HTML;
|
||||
ini_set('max_execution_time', 0);
|
||||
$excludePages = split(" *, *", $_GET['exclude']);
|
||||
|
||||
$pages = DataObject::get("SiteTree", "ParentID = 0");
|
||||
$pages = DataObject::get("SiteTree", "\"ParentID\" = 0");
|
||||
foreach($pages as $page) $pageArr[] = $page;
|
||||
|
||||
while(list($i,$page) = each($pageArr)) {
|
||||
@ -1241,7 +1241,7 @@ HTML;
|
||||
$restoredPage = Versioned::get_latest_version("SiteTree", $id);
|
||||
$restoredPage->ID = $restoredPage->RecordID;
|
||||
if(!DB::query("SELECT \"ID\" FROM \"SiteTree\" WHERE \"ID\" = $restoredPage->ID")->value()) {
|
||||
DB::query("INSERT INTO \"SiteTree\" SET \"ID\" = $restoredPage->ID");
|
||||
DB::query("INSERT INTO \"SiteTree\" (\"ID\") VALUES ($restoredPage->ID)");
|
||||
}
|
||||
$restoredPage->forceChange();
|
||||
$restoredPage->writeWithoutVersion();
|
||||
|
@ -55,17 +55,17 @@ class CommentAdmin extends LeftAndMain {
|
||||
$section = $this->Section();
|
||||
|
||||
if($section == 'approved') {
|
||||
$filter = 'IsSpam=0 AND NeedsModeration=0';
|
||||
$filter = 'NOT "IsSpam" AND NOT "NeedsModeration"';
|
||||
$title = "<h2>". _t('CommentAdmin.APPROVEDCOMMENTS', 'Approved Comments')."</h2>";
|
||||
} else if($section == 'unmoderated') {
|
||||
$filter = 'NeedsModeration=1';
|
||||
$filter = '"NeedsModeration"';
|
||||
$title = "<h2>"._t('CommentAdmin.COMMENTSAWAITINGMODERATION', 'Comments Awaiting Moderation')."</h2>";
|
||||
} else {
|
||||
$filter = 'IsSpam=1';
|
||||
$filter = '"IsSpam"';
|
||||
$title = "<h2>"._t('CommentAdmin.SPAM', 'Spam')."</h2>";
|
||||
}
|
||||
|
||||
$filter .= ' AND ParentID>0';
|
||||
$filter .= ' AND "ParentID">0';
|
||||
|
||||
$tableFields = array(
|
||||
"Name" => _t('CommentAdmin.AUTHOR', 'Author'),
|
||||
@ -125,7 +125,7 @@ class CommentAdmin extends LeftAndMain {
|
||||
|
||||
if($_REQUEST['Comments']) {
|
||||
foreach($_REQUEST['Comments'] as $commentid) {
|
||||
$comment = DataObject::get_one('PageComment', "\"PageComment\".ID = $commentid");
|
||||
$comment = DataObject::get_one('PageComment', "\"PageComment\".\"ID\" = $commentid");
|
||||
if($comment) {
|
||||
$comment->delete();
|
||||
$numComments++;
|
||||
@ -144,7 +144,7 @@ JS;
|
||||
|
||||
function deleteall() {
|
||||
$numComments = 0;
|
||||
$spam = DataObject::get('PageComment', 'PageComment.IsSpam=1');
|
||||
$spam = DataObject::get('PageComment', '"PageComment"."IsSpam"');
|
||||
|
||||
if($spam) {
|
||||
$numComments = $spam->Count();
|
||||
@ -169,7 +169,7 @@ JS;
|
||||
|
||||
if($_REQUEST['Comments']) {
|
||||
foreach($_REQUEST['Comments'] as $commentid) {
|
||||
$comment = DataObject::get_one('PageComment', "\"PageComment\".ID = $commentid");
|
||||
$comment = DataObject::get_one('PageComment', "\"PageComment\".\"ID\" = $commentid");
|
||||
if($comment) {
|
||||
$comment->IsSpam = true;
|
||||
$comment->NeedsModeration = false;
|
||||
@ -208,7 +208,7 @@ JS;
|
||||
|
||||
if($_REQUEST['Comments']) {
|
||||
foreach($_REQUEST['Comments'] as $commentid) {
|
||||
$comment = DataObject::get_one('PageComment', "\"PageComment\".ID = $commentid");
|
||||
$comment = DataObject::get_one('PageComment', "\"PageComment\".\"ID\" = $commentid");
|
||||
if($comment) {
|
||||
$comment->IsSpam = false;
|
||||
$comment->NeedsModeration = false;
|
||||
@ -248,7 +248,7 @@ JS;
|
||||
|
||||
if($_REQUEST['Comments']) {
|
||||
foreach($_REQUEST['Comments'] as $commentid) {
|
||||
$comment = DataObject::get_one('PageComment', "\"PageComment\".ID = $commentid");
|
||||
$comment = DataObject::get_one('PageComment', "\"PageComment\".\"ID\" = $commentid");
|
||||
if($comment) {
|
||||
$comment->IsSpam = false;
|
||||
$comment->NeedsModeration = false;
|
||||
@ -272,21 +272,21 @@ JS;
|
||||
* Return the number of moderated comments
|
||||
*/
|
||||
function NumModerated() {
|
||||
return DB::query("SELECT COUNT(*) FROM PageComment WHERE !IsSpam AND !NeedsModeration")->value();
|
||||
return DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE NOT \"IsSpam\" AND NOT \"NeedsModeration\"")->value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of unmoderated comments
|
||||
*/
|
||||
function NumUnmoderated() {
|
||||
return DB::query("SELECT COUNT(*) FROM PageComment WHERE !IsSpam AND NeedsModeration")->value();
|
||||
return DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE NOT \"IsSpam\" AND \"NeedsModeration\"")->value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of comments marked as spam
|
||||
*/
|
||||
function NumSpam() {
|
||||
return DB::query("SELECT COUNT(*) FROM PageComment WHERE IsSpam")->value();
|
||||
return DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE \"IsSpam\"")->value();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ class FileList extends TableListField {
|
||||
}
|
||||
|
||||
function sourceItems() {
|
||||
return DataObject::get("File", "ParentID = '" . $this->folder->ID . "' AND ClassName <> 'Folder'", "Title");
|
||||
return DataObject::get("File", "\"ParentID\" = '" . $this->folder->ID . "' AND \"ClassName\" <> 'Folder'", '"Title"');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ class ImageEditor extends Controller {
|
||||
if(strpos($originalFile,'?') !== false) $originalFile = substr($originalFile,0,strpos($originalFile,'?'));
|
||||
if($this->checkFileExists($originalFile) && $this->checkFileExists($editedFile)) {
|
||||
if($editedFile != $originalFile && copy($this->url2File($editedFile),$this->url2File($originalFile))) {
|
||||
$image = DataObject::get_one('File','Filename = \'' . substr($this->url2File($originalFile),3) . '\'');
|
||||
$image = DataObject::get_one('File','"Filename" = \'' . substr($this->url2File($originalFile),3) . '\'');
|
||||
$image->deleteFormattedImages();
|
||||
$image->generateFormattedImage('AssetLibraryPreview');
|
||||
} else {
|
||||
|
@ -85,7 +85,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
||||
$fieldVal = $_REQUEST[$fieldName];
|
||||
$result = '';
|
||||
|
||||
$matches = DataObject::get($this->stat('subitem_class'),"$fieldName LIKE '" . addslashes($fieldVal) . "%'");
|
||||
$matches = DataObject::get($this->stat('subitem_class'),"\"$fieldName\" LIKE '" . addslashes($fieldVal) . "%'");
|
||||
if($matches) {
|
||||
$result .= "<ul>";
|
||||
foreach($matches as $match) {
|
||||
@ -153,7 +153,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
||||
if($id == 'new') $id = null;
|
||||
|
||||
if($id) {
|
||||
$record = DataObject::get_one($className, "\"$className\".ID = $id");
|
||||
$record = DataObject::get_one($className, "\"$className\".\"ID\" = $id");
|
||||
} else {
|
||||
$record = new $className();
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class SideReport_EmptyPages extends SideReport {
|
||||
return _t('SideReport.EMPTYPAGES',"Empty pages");
|
||||
}
|
||||
function records() {
|
||||
return DataObject::get("SiteTree", "Content = '' OR Content IS NULL OR Content LIKE '<p></p>' OR Content LIKE '<p> </p>'", "Title");
|
||||
return DataObject::get("SiteTree", "\"Content\" = '' OR \"Content\" IS NULL OR \"Content\" LIKE '<p></p>' OR \"Content\" LIKE '<p> </p>'", '"Title"');
|
||||
}
|
||||
function fieldsToShow() {
|
||||
return array(
|
||||
@ -87,7 +87,7 @@ class SideReport_RecentlyEdited extends SideReport {
|
||||
return _t('SideReport.LAST2WEEKS',"Pages edited in the last 2 weeks");
|
||||
}
|
||||
function records() {
|
||||
return DataObject::get("SiteTree", "\"SiteTree\".LastEdited > NOW() - INTERVAL 14 DAY", "\"SiteTree\".\"LastEdited\" DESC");
|
||||
return DataObject::get("SiteTree", "\"SiteTree\".\"LastEdited\" > NOW() - INTERVAL 14 DAY", "\"SiteTree\".\"LastEdited\" DESC");
|
||||
}
|
||||
function fieldsToShow() {
|
||||
return array(
|
||||
@ -101,7 +101,7 @@ class SideReport_ToDo extends SideReport {
|
||||
return _t('SideReport.TODO',"To do");
|
||||
}
|
||||
function records() {
|
||||
return DataObject::get("SiteTree", "\"SiteTree\".ToDo IS NOT NULL AND \"SiteTree\".ToDo <> ''", "\"SiteTree\".\"LastEdited\" DESC");
|
||||
return DataObject::get("SiteTree", "\"SiteTree\".\"ToDo\" IS NOT NULL AND \"SiteTree\".\"ToDo\" <> ''", "\"SiteTree\".\"LastEdited\" DESC");
|
||||
}
|
||||
function fieldsToShow() {
|
||||
return array(
|
||||
|
@ -47,14 +47,14 @@ class ThumbnailStripField extends FormField {
|
||||
$folderList = $folder->getDescendantIDList('Folder');
|
||||
array_unshift($folderList, $folder->ID);
|
||||
|
||||
$whereSQL = 'ParentID IN (' . implode(', ', $folderList) . ')';
|
||||
if($searchText) $whereSQL .= " AND Filename LIKE '%$searchText%'";
|
||||
$whereSQL = '"ParentID" IN (' . implode(', ', $folderList) . ')';
|
||||
if($searchText) $whereSQL .= " AND \"Filename\" LIKE '%$searchText%'";
|
||||
|
||||
$images = DataObject::get('Image', $whereSQL, 'Title');
|
||||
|
||||
} else {
|
||||
if($searchText) {
|
||||
$whereSQL = "Filename LIKE '%$searchText%'";
|
||||
$whereSQL = "\"Filename\" LIKE '%$searchText%'";
|
||||
|
||||
$images = DataObject::get('Image', $whereSQL, 'Title');
|
||||
}
|
||||
@ -113,13 +113,13 @@ class ThumbnailStripField extends FormField {
|
||||
$folderList = $folder->getDescendantIDList('Folder');
|
||||
array_unshift($folderList, $folder->ID);
|
||||
|
||||
$whereSQL = "ParentID IN (" . implode(', ', $folderList) . ") AND Filename LIKE '%.swf'";
|
||||
if($searchText) $whereSQL .= " AND Filename LIKE '%$searchText%'";
|
||||
$whereSQL = "\"ParentID\" IN (" . implode(', ', $folderList) . ") AND \"Filename\" LIKE '%.swf'";
|
||||
if($searchText) $whereSQL .= " AND \"Filename\" LIKE '%$searchText%'";
|
||||
|
||||
$flashObjects = DataObject::get('File', $whereSQL);
|
||||
} else {
|
||||
if($searchText) {
|
||||
$flashObjects = DataObject::get('File', "Filename LIKE '%$searchText%' AND Filename LIKE '%.swf'");
|
||||
$flashObjects = DataObject::get('File', "\"Filename\" LIKE '%$searchText%' AND \"Filename\" LIKE '%.swf'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,8 +123,8 @@ class PageComment extends DataObject {
|
||||
|
||||
class PageComment_Controller extends Controller {
|
||||
function rss() {
|
||||
$parentcheck = isset($_REQUEST['pageid']) ? "ParentID = " . (int) $_REQUEST['pageid'] : "ParentID > 0";
|
||||
$comments = DataObject::get("PageComment", "$parentcheck AND IsSpam=0", "Created DESC", "", 10);
|
||||
$parentcheck = isset($_REQUEST['pageid']) ? "\"ParentID\" = " . (int) $_REQUEST['pageid'] : "\"ParentID\" > 0";
|
||||
$comments = DataObject::get("PageComment", "$parentcheck AND NOT \"IsSpam\"", "\"Created\" DESC", "", 10);
|
||||
if(!isset($comments)) {
|
||||
$comments = new DataObjectSet();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class SiteTreeMaintenanceTask extends Controller {
|
||||
|
||||
function makelinksunique() {
|
||||
$badURLs = "'" . implode("', '", DB::query("SELECT URLSegment, count(*) FROM SiteTree GROUP BY URLSegment HAVING count(*) > 1")->column()) . "'";
|
||||
$pages = DataObject::get("SiteTree", "URLSegment IN ($badURLs)");
|
||||
$pages = DataObject::get("SiteTree", "\"URLSegment\" IN ($badURLs)");
|
||||
|
||||
foreach($pages as $page) {
|
||||
echo "<li>$page->Title: ";
|
||||
|
Loading…
Reference in New Issue
Block a user