Commit 250cf34d authored by Nigel McNie's avatar Nigel McNie Committed by Penny Leach
Browse files

Change to how table names are specified in SQL queries.

Now, table names (and other identifiers that could be confused with SQL kewords), should be put into SQL like this:

SELECT * FROM {artefact}

The braces are matched and expanded by DML now to include the prefix and be properly quoted, which means that tables like 'view' and 'group' don't need renaming (and nor should they, there's little reason why we should rename tables to get around such constraints).

This has removed a whole bunch of $prefix = ... and get_config('dbprefix') stuff, which makes things a little simpler yet again.
parent 7f278a16
...@@ -59,7 +59,6 @@ $limit = param_integer('limit', 10); ...@@ -59,7 +59,6 @@ $limit = param_integer('limit', 10);
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$userid = $USER->get('id'); $userid = $USER->get('id');
$prefix = get_config('dbprefix');
if ($type == 'all') { if ($type == 'all') {
$count = count_records('notification_internal_activity', 'usr', $userid); $count = count_records('notification_internal_activity', 'usr', $userid);
...@@ -67,10 +66,10 @@ if ($type == 'all') { ...@@ -67,10 +66,10 @@ if ($type == 'all') {
'ctime DESC', '*', $offset, $limit); 'ctime DESC', '*', $offset, $limit);
} else if ($type == 'adminmessages' && $USER->get('admin')) { } else if ($type == 'adminmessages' && $USER->get('admin')) {
$count = count_records_select('notification_internal_activity', 'usr = ? AND type IN ( $count = count_records_select('notification_internal_activity', 'usr = ? AND type IN (
SELECT name FROM ' . $prefix . 'activity_type WHERE admin = ?)', SELECT name FROM {activity_type} WHERE admin = ?)',
array($userid, 1)); array($userid, 1));
$records = get_records_select_array('notification_internal_activity', 'usr = ? AND type IN ( $records = get_records_select_array('notification_internal_activity', 'usr = ? AND type IN (
SELECT name FROM ' . $prefix . 'activity_type WHERE admin = ?)', SELECT name FROM {activity_type} WHERE admin = ?)',
array($userid, 1), array($userid, 1),
'ctime DESC', '*', $offset, $limit); 'ctime DESC', '*', $offset, $limit);
} }
......
...@@ -35,7 +35,6 @@ $stopmonitoring = param_integer('stopmonitoring', 0); ...@@ -35,7 +35,6 @@ $stopmonitoring = param_integer('stopmonitoring', 0);
$userlist = param_alpha('userlist', null); $userlist = param_alpha('userlist', null);
$getartefacts = param_integer('getartefacts', 0); $getartefacts = param_integer('getartefacts', 0);
$prefix = get_config('dbprefix');
$userid = $USER->get('id'); $userid = $USER->get('id');
if ($stopmonitoring) { if ($stopmonitoring) {
...@@ -68,9 +67,9 @@ if ($stopmonitoring) { ...@@ -68,9 +67,9 @@ if ($stopmonitoring) {
if (!empty($userlist)) { if (!empty($userlist)) {
if ($userlist == 'views') { if ($userlist == 'views') {
$sql = 'SELECT DISTINCT u.* $sql = 'SELECT DISTINCT u.*
FROM ' . $prefix . 'usr u FROM {usr} u
JOIN ' . $prefix . 'view v ON v.owner = u.id JOIN {view} v ON v.owner = u.id
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id JOIN {usr_watchlist_view} w ON w.view = v.id
WHERE w.usr = ?'; WHERE w.usr = ?';
if (!$users = get_records_sql_array($sql, array($userid))) { if (!$users = get_records_sql_array($sql, array($userid))) {
...@@ -79,9 +78,9 @@ if (!empty($userlist)) { ...@@ -79,9 +78,9 @@ if (!empty($userlist)) {
} }
else if ($userlist == 'artefacts') { else if ($userlist == 'artefacts') {
$sql = 'SELECT DISTINCT u.* $sql = 'SELECT DISTINCT u.*
FROM ' . $prefix . 'usr u FROM {usr} u
JOIN ' . $prefix . 'artefact a ON a.owner = u.id JOIN {artefact} a ON a.owner = u.id
JOIN ' . $prefix . 'usr_watchlist_artefact w ON w.artefact = a.id JOIN {usr_watchlist_artefact} w ON w.artefact = a.id
WHERE w.usr = ?'; WHERE w.usr = ?';
if (!$users = get_records_sql_array($sql, array($userid))) { if (!$users = get_records_sql_array($sql, array($userid))) {
...@@ -107,7 +106,6 @@ $limit = param_integer('limit', 10); ...@@ -107,7 +106,6 @@ $limit = param_integer('limit', 10);
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$userid = $USER->get('id'); $userid = $USER->get('id');
$prefix = get_config('dbprefix');
$count = 0; $count = 0;
$records = array(); $records = array();
...@@ -115,8 +113,8 @@ $records = array(); ...@@ -115,8 +113,8 @@ $records = array();
if ($type == 'views') { if ($type == 'views') {
$count = count_records('usr_watchlist_view', 'usr', $userid); $count = count_records('usr_watchlist_view', 'usr', $userid);
$sql = 'SELECT v.*, v.title AS name, w.recurse $sql = 'SELECT v.*, v.title AS name, w.recurse
FROM ' . $prefix . 'view v FROM {view} v
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id JOIN {usr_watchlist_view} w ON w.view = v.id
WHERE w.usr = ?'; WHERE w.usr = ?';
$values = array($userid); $values = array($userid);
if (isset($owner)) { if (isset($owner)) {
...@@ -129,18 +127,18 @@ if ($type == 'views') { ...@@ -129,18 +127,18 @@ if ($type == 'views') {
} }
else if ($type == 'groups') { else if ($type == 'groups') {
$count = count_records('usr_watchlist_group', 'usr', $userid); $count = count_records('usr_watchlist_group', 'usr', $userid);
$sql = 'SELECT c.* $sql = 'SELECT g.*
FROM ' . $prefix . 'group g FROM {group} g
JOIN ' . $prefix . 'usr_watchlist_group w ON w.group = g.id JOIN {usr_watchlist_group} w ON w.group = g.id
WHERE w.usr = ? WHERE w.usr = ?
ORDER BY c.mtime DESC'; ORDER BY g.mtime DESC';
$records = get_records_sql_array($sql, array($userid), $offset, $limit); $records = get_records_sql_array($sql, array($userid), $offset, $limit);
} }
else if ($type == 'artefacts') { else if ($type == 'artefacts') {
$count = count_records('usr_watchlist_artefact', 'usr', $userid); $count = count_records('usr_watchlist_artefact', 'usr', $userid);
$sql = 'SELECT a.* , a.title AS name, w.view, w.recurse $sql = 'SELECT a.* , a.title AS name, w.view, w.recurse
FROM ' . $prefix . 'artefact a FROM {artefact} a
JOIN ' . $prefix . 'usr_watchlist_artefact w ON w.artefact = a.id JOIN {usr_watchlist_artefact} w ON w.artefact = a.id
WHERE w.usr = ?'; WHERE w.usr = ?';
$values = array($userid); $values = array($userid);
if (isset($owner)) { if (isset($owner)) {
......
...@@ -159,11 +159,10 @@ function statusChange() { ...@@ -159,11 +159,10 @@ function statusChange() {
JAVASCRIPT; JAVASCRIPT;
$prefix = get_config('dbprefix');
$sql = 'SELECT DISTINCT u.* $sql = 'SELECT DISTINCT u.*
FROM ' . $prefix . 'usr u FROM {usr} u
JOIN ' . $prefix . 'view v ON v.owner = u.id JOIN {view} v ON v.owner = u.id
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id JOIN {usr_watchlist_view} w ON w.view = v.id
WHERE w.usr = ?'; WHERE w.usr = ?';
if (!$viewusers = get_records_sql_array($sql, array($USER->get('id')))) { if (!$viewusers = get_records_sql_array($sql, array($USER->get('id')))) {
......
...@@ -35,12 +35,11 @@ $public = (int) param_boolean('public'); ...@@ -35,12 +35,11 @@ $public = (int) param_boolean('public');
$result = array(); $result = array();
//$menuitems = get_records_array('site_menu','public',$public,'displayorder'); //$menuitems = get_records_array('site_menu','public',$public,'displayorder');
$prefix = get_config('dbprefix');
$menuitems = get_records_sql_array(' $menuitems = get_records_sql_array('
SELECT SELECT
s.*, a.title AS filename s.*, a.title AS filename
FROM ' . $prefix . 'site_menu s FROM {site_menu} s
LEFT OUTER JOIN ' . $prefix . 'artefact a ON s.file = a.id LEFT OUTER JOIN {artefact} a ON s.file = a.id
WHERE WHERE
s.public = ' . $public . ' s.public = ' . $public . '
ORDER BY s.displayorder', null); ORDER BY s.displayorder', null);
......
...@@ -65,18 +65,17 @@ $form = array( ...@@ -65,18 +65,17 @@ $form = array(
function adminusers_submit(Pieform $form, $values) { function adminusers_submit(Pieform $form, $values) {
global $SESSION; global $SESSION;
$table = get_config('dbprefix') . 'usr';
db_begin(); db_begin();
execute_sql('UPDATE ' . $table . ' execute_sql('UPDATE {usr}
SET admin = 0 SET admin = 0
WHERE admin = 1'); WHERE admin = 1');
execute_sql('UPDATE ' . $table . ' execute_sql('UPDATE {usr}
SET admin = 1 SET admin = 1
WHERE id IN (' . join(',', $values['users']) . ')'); WHERE id IN (' . join(',', $values['users']) . ')');
execute_sql('DELETE FROM ' . get_config('dbprefix') . 'usr_activity_preference execute_sql('DELETE FROM {usr_activity_preference}
WHERE activity IN (SELECT name FROM ' . get_config('dbprefix') . 'activity_type WHERE activity IN (SELECT name FROM {activity_type}
WHERE admin = 1 ) WHERE admin = 1)
AND usr NOT IN (' . join(',', $values['users']) . ')'); AND usr NOT IN (' . join(',', $values['users']) . ')');
db_commit(); db_commit();
$SESSION->add_ok_msg(get_string('adminusersupdated', 'admin')); $SESSION->add_ok_msg(get_string('adminusersupdated', 'admin'));
......
...@@ -225,10 +225,9 @@ if ($institution || $add) { ...@@ -225,10 +225,9 @@ if ($institution || $add) {
} }
else { else {
// Get a list of institutions // Get a list of institutions
$prefix = get_config('dbprefix');
$institutions = get_records_sql_array('SELECT i.name, i.displayname, i.registerallowed, COUNT(u.id) AS hasmembers $institutions = get_records_sql_array('SELECT i.name, i.displayname, i.registerallowed, COUNT(u.id) AS hasmembers
FROM ' . $prefix . 'institution i FROM {institution} i
LEFT OUTER JOIN ' . $prefix . 'usr u ON (u.institution = i.name) LEFT OUTER JOIN {usr} u ON (u.institution = i.name)
GROUP BY 1, 2, 3 GROUP BY 1, 2, 3
ORDER BY i.name', array()); ORDER BY i.name', array());
$smarty->assign('institutions', $institutions); $smarty->assign('institutions', $institutions);
......
...@@ -36,11 +36,9 @@ define('SECTION_PAGE', 'notifications'); ...@@ -36,11 +36,9 @@ define('SECTION_PAGE', 'notifications');
require_once('pieforms/pieform.php'); require_once('pieforms/pieform.php');
$prefix = get_config('dbprefix');
$sql = 'SELECT u.*, a.activity, a.method $sql = 'SELECT u.*, a.activity, a.method
FROM ' . $prefix . 'usr u FROM {usr} u
LEFT JOIN ' . $prefix . 'usr_activity_preference a ON a.usr = u.id LEFT JOIN {usr_activity_preference} a ON a.usr = u.id
WHERE u.admin = ?'; WHERE u.admin = ?';
$admins = get_records_sql_array($sql, array(1)); $admins = get_records_sql_array($sql, array(1));
......
...@@ -30,7 +30,6 @@ define('JSON', 1); ...@@ -30,7 +30,6 @@ define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php'); require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$action = param_variable('action'); $action = param_variable('action');
$dbprefix = get_config('dbprefix');
if ($action == 'suspend') { if ($action == 'suspend') {
$id = param_integer('id'); $id = param_integer('id');
......
...@@ -61,14 +61,13 @@ $form = array( ...@@ -61,14 +61,13 @@ $form = array(
function staffusers_submit(Pieform $form, $values) { function staffusers_submit(Pieform $form, $values) {
global $SESSION; global $SESSION;
$table = get_config('dbprefix') . 'usr';
db_begin(); db_begin();
execute_sql('UPDATE ' . $table . ' execute_sql('UPDATE {usr}
SET staff = 0 SET staff = 0
WHERE staff = 1'); WHERE staff = 1');
if ($values['users']) { if ($values['users']) {
execute_sql('UPDATE ' . $table . ' execute_sql('UPDATE {usr}
SET staff = 1 SET staff = 1
WHERE id IN (' . join(',', $values['users']) . ')'); WHERE id IN (' . join(',', $values['users']) . ')');
} }
......
...@@ -35,16 +35,14 @@ json_headers(); ...@@ -35,16 +35,14 @@ json_headers();
$limit = param_integer('limit', 10); $limit = param_integer('limit', 10);
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$dbprefix = get_config('dbprefix');
// NOTE: the check is not done on the 'active' column here, since suspended // NOTE: the check is not done on the 'active' column here, since suspended
// users are by definition not active. However deleted users are filtered out. // users are by definition not active. However deleted users are filtered out.
$count = get_field_sql('SELECT COUNT(*) FROM ' . $dbprefix . 'usr WHERE suspendedcusr IS NOT NULL AND deleted = 0'); $count = get_field_sql('SELECT COUNT(*) FROM {usr} WHERE suspendedcusr IS NOT NULL AND deleted = 0');
$data = get_records_sql_array('SELECT u.id, u.firstname, u.lastname, u.studentid, u.suspendedreason AS reason, $data = get_records_sql_array('SELECT u.id, u.firstname, u.lastname, u.studentid, u.suspendedreason AS reason,
i.displayname AS institution, ua.firstname AS cusrfirstname, ua.lastname AS cusrlastname i.displayname AS institution, ua.firstname AS cusrfirstname, ua.lastname AS cusrlastname
FROM ' . $dbprefix . 'usr u FROM {usr} u
LEFT JOIN ' . $dbprefix . 'institution i ON (u.institution = i.name) LEFT JOIN {institution} i ON (u.institution = i.name)
LEFT JOIN ' . $dbprefix . 'usr ua on (ua.id = u.suspendedcusr) LEFT JOIN {usr} ua on (ua.id = u.suspendedcusr)
WHERE u.suspendedcusr IS NOT NULL WHERE u.suspendedcusr IS NOT NULL
AND u.deleted = 0 AND u.deleted = 0
ORDER BY u.suspendedctime ORDER BY u.suspendedctime
......
...@@ -84,8 +84,6 @@ function auth_get_auth_instances() { ...@@ -84,8 +84,6 @@ function auth_get_auth_instances() {
return $cache; return $cache;
} }
$dbprefix = get_config('dbprefix');
$sql =' $sql ='
SELECT DISTINCT SELECT DISTINCT
i.id, i.id,
...@@ -93,8 +91,8 @@ function auth_get_auth_instances() { ...@@ -93,8 +91,8 @@ function auth_get_auth_instances() {
inst.displayname, inst.displayname,
i.instancename i.instancename
FROM FROM
'.$dbprefix.'institution inst, {institution} inst,
'.$dbprefix.'auth_instance i {auth_instance} i
WHERE WHERE
i.institution = inst.name i.institution = inst.name
ORDER BY ORDER BY
......
...@@ -132,16 +132,15 @@ function fetch_user_image($username) { ...@@ -132,16 +132,15 @@ function fetch_user_image($username) {
throw new XmlrpcServerException('Unknown error'); throw new XmlrpcServerException('Unknown error');
} }
$dbprefix = get_config('dbprefix');
$authinstances = auth_get_auth_instances_for_institution($institution); $authinstances = auth_get_auth_instances_for_institution($institution);
$candidates = array(); $candidates = array();
$sql = 'SElECT $sql = 'SElECT
ai.* ai.*
FROM FROM
'.$dbprefix.'auth_instance ai, {auth_instance} ai,
'.$dbprefix.'auth_instance ai2, {auth_instance} ai2,
'.$dbprefix.'auth_instance_config aic {auth_instance_config} aic
WHERE WHERE
ai.id = ? AND ai.id = ? AND
ai.institution = ? AND ai.institution = ? AND
...@@ -274,8 +273,6 @@ function get_service_providers($instance) { ...@@ -274,8 +273,6 @@ function get_service_providers($instance) {
return $cache[$instance]; return $cache[$instance];
} }
$dbprefix = get_config('dbprefix');
$query = ' $query = '
SELECT SELECT
h.name, h.name,
...@@ -283,11 +280,11 @@ function get_service_providers($instance) { ...@@ -283,11 +280,11 @@ function get_service_providers($instance) {
h.wwwroot, h.wwwroot,
aic.instance aic.instance
FROM FROM
'.$dbprefix.'auth_instance_config aic, {auth_instance_config} aic,
'.$dbprefix.'auth_instance_config aic2, {auth_instance_config} aic2,
'.$dbprefix.'auth_instance_config aic3, {auth_instance_config} aic3,
'.$dbprefix.'host h, {host} h,
'.$dbprefix.'application a {application} a
WHERE WHERE
((aic.value = 1 AND ((aic.value = 1 AND
aic.field = \'theyautocreateusers\' ) OR aic.field = \'theyautocreateusers\' ) OR
......
...@@ -339,7 +339,7 @@ class ArtefactTypeBlog extends ArtefactType { ...@@ -339,7 +339,7 @@ class ArtefactTypeBlog extends ArtefactType {
public static function get_blog_list(User $user, $limit = self::pagination, $offset = 0) { public static function get_blog_list(User $user, $limit = self::pagination, $offset = 0) {
($result = get_records_sql_array(" ($result = get_records_sql_array("
SELECT id, title, description SELECT id, title, description
FROM " . get_config('dbprefix') . "artefact FROM {artefact}
WHERE owner = ? WHERE owner = ?
AND artefacttype = 'blog' AND artefacttype = 'blog'
ORDER BY title ORDER BY title
...@@ -632,11 +632,10 @@ class ArtefactTypeBlogPost extends ArtefactType { ...@@ -632,11 +632,10 @@ class ArtefactTypeBlogPost extends ArtefactType {
* @param integer * @param integer
*/ */
public static function get_posts(User $user, $id, $limit = self::pagination, $offset = 0) { public static function get_posts(User $user, $id, $limit = self::pagination, $offset = 0) {
$prefix = get_config('dbprefix');
($result = get_records_sql_assoc(" ($result = get_records_sql_assoc("
SELECT a.id, a.title, a.description, a.ctime, a.mtime, bp.published SELECT a.id, a.title, a.description, a.ctime, a.mtime, bp.published
FROM " . $prefix . "artefact a FROM {artefact} a
LEFT OUTER JOIN " . $prefix . "artefact_blog_blogpost bp LEFT OUTER JOIN {artefact_blog_blogpost} bp
ON a.id = bp.blogpost ON a.id = bp.blogpost
WHERE a.parent = ? WHERE a.parent = ?
AND a.artefacttype = 'blogpost' AND a.artefacttype = 'blogpost'
...@@ -659,8 +658,8 @@ class ArtefactTypeBlogPost extends ArtefactType { ...@@ -659,8 +658,8 @@ class ArtefactTypeBlogPost extends ArtefactType {
$files = get_records_sql_array(' $files = get_records_sql_array('
SELECT SELECT
bf.blogpost, bf.file, a.artefacttype, a.title, a.description bf.blogpost, bf.file, a.artefacttype, a.title, a.description
FROM ' . $prefix . 'artefact_blog_blogpost_file bf FROM {artefact_blog_blogpost_file} bf
INNER JOIN ' . $prefix . 'artefact a ON bf.file = a.id INNER JOIN {artefact} a ON bf.file = a.id
WHERE bf.blogpost IN (' . $idlist . ')', ''); WHERE bf.blogpost IN (' . $idlist . ')', '');
if ($files) { if ($files) {
foreach ($files as $file) { foreach ($files as $file) {
...@@ -683,8 +682,8 @@ class ArtefactTypeBlogPost extends ArtefactType { ...@@ -683,8 +682,8 @@ class ArtefactTypeBlogPost extends ArtefactType {
public static function render_posts($format, $options, $id, $limit = self::pagination, $offset = 0) { public static function render_posts($format, $options, $id, $limit = self::pagination, $offset = 0) {
($postids = get_records_sql_array(" ($postids = get_records_sql_array("
SELECT a.id SELECT a.id
FROM " . get_config('dbprefix') . "artefact a FROM {artefact} a
LEFT OUTER JOIN " . get_config('dbprefix') . "artefact_blog_blogpost bp LEFT OUTER JOIN {artefact_blog_blogpost} bp
ON a.id = bp.blogpost ON a.id = bp.blogpost
WHERE a.parent = ? WHERE a.parent = ?
AND bp.published = 1 AND bp.published = 1
...@@ -703,8 +702,8 @@ class ArtefactTypeBlogPost extends ArtefactType { ...@@ -703,8 +702,8 @@ class ArtefactTypeBlogPost extends ArtefactType {
$count = (int)get_field_sql(" $count = (int)get_field_sql("
SELECT COUNT(*) SELECT COUNT(*)
FROM " . get_config('dbprefix') . "artefact a FROM {artefact} a
LEFT OUTER JOIN " . get_config('dbprefix') . "artefact_blog_blogpost bp LEFT OUTER JOIN {artefact_blog_blogpost} bp
ON a.id = bp.blogpost ON a.id = bp.blogpost
WHERE a.parent = ? WHERE a.parent = ?
AND bp.published = 1", array($id)); AND bp.published = 1", array($id));
...@@ -857,10 +856,9 @@ class ArtefactTypeBlogPost extends ArtefactType { ...@@ -857,10 +856,9 @@ class ArtefactTypeBlogPost extends ArtefactType {
* @return array * @return array
*/ */
public function get_attached_files() { public function get_attached_files() {
$prefix = get_config('dbprefix');
$list = get_records_sql_array('SELECT a.id, a.artefacttype, a.title, a.description $list = get_records_sql_array('SELECT a.id, a.artefacttype, a.title, a.description
FROM ' . $prefix . 'artefact_blog_blogpost_file f FROM {artefact_blog_blogpost_file} f
INNER JOIN ' . $prefix . 'artefact a ON a.id = f.file INNER JOIN {artefact} a ON a.id = f.file
WHERE f.blogpost = ' . $this->id, ''); WHERE f.blogpost = ' . $this->id, '');
// load tags // load tags
......
...@@ -38,11 +38,10 @@ function xmldb_artefact_file_upgrade($oldversion=0) { ...@@ -38,11 +38,10 @@ function xmldb_artefact_file_upgrade($oldversion=0) {
set_field('artefact_file_files', 'adminfiles', 0); set_field('artefact_file_files', 'adminfiles', 0);
// Put all folders into artefact_file_files // Put all folders into artefact_file_files
$prefix = get_config('dbprefix');
$folders = get_column_sql(" $folders = get_column_sql("
SELECT a.id SELECT a.id
FROM " . $prefix . "artefact a FROM {artefact} a
LEFT OUTER JOIN " . $prefix . "artefact_file_files f ON a.id = f.artefact LEFT OUTER JOIN {artefact_file_files} f ON a.id = f.artefact
WHERE a.artefacttype = 'folder' AND f.artefact IS NULL"); WHERE a.artefacttype = 'folder' AND f.artefact IS NULL");
if ($folders) { if ($folders) {
foreach ($folders as $folderid) { foreach ($folders as $folderid) {
...@@ -124,10 +123,9 @@ function xmldb_artefact_file_upgrade($oldversion=0) { ...@@ -124,10 +123,9 @@ function xmldb_artefact_file_upgrade($oldversion=0) {
if ($oldversion < 2007042500) { if ($oldversion < 2007042500) {
// migrate everything we had to change to make mysql happy // migrate everything we had to change to make mysql happy
$prefix = get_config('dbprefix'); execute_sql("ALTER TABLE {artefact_file_file_types} ALTER COLUMN description TYPE varchar(32)");
execute_sql("ALTER TABLE {$prefix}artefact_file_file_types ALTER COLUMN description TYPE varchar(32)"); execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN mimetype TYPE varchar(128)");
execute_sql("ALTER TABLE {$prefix}artefact_file_mime_types ALTER COLUMN mimetype TYPE varchar(128)"); execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN description TYPE varchar(32)");
execute_sql("ALTER TABLE {$prefix}artefact_file_mime_types ALTER COLUMN description TYPE varchar(32)");
} }
......
...@@ -353,10 +353,9 @@ abstract class ArtefactTypeFileBase extends ArtefactType { ...@@ -353,10 +353,9 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
// Check if something exists in the db with a given title and parent, // Check if something exists in the db with a given title and parent,
// either in adminfiles or with a specific owner. // either in adminfiles or with a specific owner.
public static function file_exists($title, $owner, $folder, $adminfiles=false) { public static function file_exists($title, $owner, $folder, $adminfiles=false) {
$prefix = get_config('dbprefix');
$filetypesql = "('" . join("','", PluginArtefactFile::get_artefact_types()) . "')"; $filetypesql = "('" . join("','", PluginArtefactFile::get_artefact_types()) . "')";
return get_field_sql('SELECT a.id FROM ' . $prefix . 'artefact a return get_field_sql('SELECT a.id FROM {artefact} a
LEFT OUTER JOIN ' . $prefix . 'artefact_file_files f ON f.artefact = a.id LEFT OUTER JOIN {artefact_file_files} f ON f.artefact = a.id
WHERE ' . ($adminfiles ? 'f.adminfiles = 1' : 'f.adminfiles <> 1 AND a.owner = ' . $owner) . ' WHERE ' . ($adminfiles ? 'f.adminfiles = 1' : 'f.adminfiles <> 1 AND a.owner = ' . $owner) . '
AND a.title = ? AND a.title = ?
AND a.parent ' . (empty($folder) ? ' IS NULL' : ' = ' . $folder) . ' AND a.parent ' . (empty($folder) ? ' IS NULL' : ' = ' . $folder) . '
...@@ -373,8 +372,6 @@ abstract class ArtefactTypeFileBase extends ArtefactType { ...@@ -373,8 +372,6 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
public static function get_my_files_data($parentfolderid, $userid, $adminfiles=false) { public static function get_my_files_data($parentfolderid, $userid, $adminfiles=false) {
$prefix = get_config('dbprefix');
$foldersql = $parentfolderid ? ' = ' . $parentfolderid : ' IS NULL'; $foldersql = $parentfolderid ? ' = ' . $parentfolderid : ' IS NULL';
// if blogs are installed then also return the number of blog // if blogs are installed then also return the number of blog
...@@ -387,11 +384,11 @@ abstract class ArtefactTypeFileBase extends ArtefactType { ...@@ -387,11 +384,11 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
a.id, a.artefacttype, a.mtime, f.size, a.title, a.description, a.id, a.artefacttype, a.mtime, f.size, a.title, a.description,
COUNT(c.id) AS childcount '