mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-26 19:29:58 +03:00
replace some mass_updates/inserts by single_update/insert
git-svn-id: http://piwigo.org/svn/trunk@25019 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
ae707279a1
commit
4926fced5e
6 changed files with 53 additions and 100 deletions
|
@ -114,8 +114,7 @@ if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) )
|
|||
//--------------------------------------------------------- form criteria check
|
||||
if (isset($_POST['submit']))
|
||||
{
|
||||
$data =
|
||||
array(
|
||||
$data = array(
|
||||
'id' => $_GET['cat_id'],
|
||||
'name' => @$_POST['name'],
|
||||
'comment' =>
|
||||
|
@ -128,13 +127,10 @@ if (isset($_POST['submit']))
|
|||
$data['commentable'] = isset($_POST['commentable'])?$_POST['commentable']:'false';
|
||||
}
|
||||
|
||||
mass_updates(
|
||||
single_update(
|
||||
CATEGORIES_TABLE,
|
||||
array(
|
||||
'primary' => array('id'),
|
||||
'update' => array_diff(array_keys($data), array('id'))
|
||||
),
|
||||
array($data)
|
||||
$data,
|
||||
array('id' => $data['id'])
|
||||
);
|
||||
|
||||
// retrieve cat infos before continuing (following updates are expensive)
|
||||
|
|
|
@ -1816,34 +1816,25 @@ SELECT id
|
|||
|
||||
if (count($existing_tags) == 0)
|
||||
{
|
||||
mass_inserts(
|
||||
single_insert(
|
||||
TAGS_TABLE,
|
||||
array('name', 'url_name'),
|
||||
array(
|
||||
array(
|
||||
'name' => $tag_name,
|
||||
'url_name' => trigger_event('render_tag_url', $tag_name),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$inserted_id = pwg_db_insert_id(TAGS_TABLE);
|
||||
|
||||
return array(
|
||||
'info' => sprintf(
|
||||
l10n('Tag "%s" was added'),
|
||||
stripslashes($tag_name)
|
||||
),
|
||||
'info' => l10n('Tag "%s" was added', stripslashes($tag_name)),
|
||||
'id' => $inserted_id,
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return array(
|
||||
'error' => sprintf(
|
||||
l10n('Tag "%s" already exists'),
|
||||
stripslashes($tag_name)
|
||||
)
|
||||
'error' => l10n('Tag "%s" already exists', stripslashes($tag_name))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,13 +154,10 @@ if (isset($_POST['submit']) and count($page['errors']) == 0)
|
|||
$data{'date_creation'} = null;
|
||||
}
|
||||
|
||||
mass_updates(
|
||||
single_update(
|
||||
IMAGES_TABLE,
|
||||
array(
|
||||
'primary' => array('id'),
|
||||
'update' => array_diff(array_keys($data), array('id'))
|
||||
),
|
||||
array($data)
|
||||
$data,
|
||||
array('id' => $data['id'])
|
||||
);
|
||||
|
||||
// time to deal with tags
|
||||
|
|
|
@ -129,16 +129,14 @@ SELECT id, name
|
|||
}
|
||||
else if (!empty($tag_name))
|
||||
{
|
||||
mass_inserts(
|
||||
single_insert(
|
||||
TAGS_TABLE,
|
||||
array('name', 'url_name'),
|
||||
array(
|
||||
array(
|
||||
'name' => $tag_name,
|
||||
'url_name' => trigger_event('render_tag_url', $tag_name),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$query = '
|
||||
SELECT id
|
||||
FROM '.TAGS_TABLE.'
|
||||
|
@ -146,6 +144,7 @@ SELECT id, name
|
|||
;';
|
||||
$destination_tag = array_from_query($query, 'id');
|
||||
$destination_tag_id = $destination_tag[0];
|
||||
|
||||
$query = '
|
||||
SELECT
|
||||
image_id
|
||||
|
@ -153,6 +152,7 @@ SELECT id, name
|
|||
WHERE tag_id = '.$tag_id.'
|
||||
;';
|
||||
$destination_tag_image_ids = array_from_query($query, 'image_id');
|
||||
|
||||
$inserts = array();
|
||||
foreach ($destination_tag_image_ids as $image_id)
|
||||
{
|
||||
|
@ -179,6 +179,7 @@ SELECT id, name
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
mass_updates(
|
||||
TAGS_TABLE,
|
||||
array(
|
||||
|
@ -323,34 +324,15 @@ if (isset($_GET['action']) and 'delete_orphans' == $_GET['action'])
|
|||
|
||||
if (isset($_POST['add']) and !empty($_POST['add_tag']))
|
||||
{
|
||||
$tag_name = $_POST['add_tag'];
|
||||
$ret = create_tag($_POST['add_tag']);
|
||||
|
||||
// does the tag already exists?
|
||||
$query = '
|
||||
SELECT id
|
||||
FROM '.TAGS_TABLE.'
|
||||
WHERE name = \''.$tag_name.'\'
|
||||
;';
|
||||
$existing_tags = array_from_query($query, 'id');
|
||||
|
||||
if (count($existing_tags) == 0)
|
||||
if (isset($ret['error']))
|
||||
{
|
||||
mass_inserts(
|
||||
TAGS_TABLE,
|
||||
array('name', 'url_name'),
|
||||
array(
|
||||
array(
|
||||
'name' => $tag_name,
|
||||
'url_name' => trigger_event('render_tag_url', $tag_name),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$page['infos'][] = l10n('Tag "%s" was added', stripslashes($tag_name));
|
||||
$page['errors'][] = $ret['error'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$page['errors'][] = l10n('Tag "%s" already exists', stripslashes($tag_name));
|
||||
$page['infos'][] = $ret['info'];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ SELECT MAX('.$conf['user_fields']['id'].') + 1
|
|||
$conf['user_fields']['email'] => $mail_address
|
||||
);
|
||||
|
||||
mass_inserts(USERS_TABLE, array_keys($insert), array($insert));
|
||||
single_insert(USERS_TABLE, $insert);
|
||||
|
||||
// Assign by default groups
|
||||
{
|
||||
|
@ -435,11 +435,9 @@ DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
|
|||
// Due to concurrency issues, we ask MySQL to ignore errors on
|
||||
// insert. This may happen when cache needs refresh and that Piwigo is
|
||||
// called "very simultaneously".
|
||||
mass_inserts
|
||||
(
|
||||
mass_inserts(
|
||||
USER_CACHE_CATEGORIES_TABLE,
|
||||
array
|
||||
(
|
||||
array(
|
||||
'user_id', 'cat_id',
|
||||
'date_last', 'max_date_last', 'nb_images', 'count_images', 'nb_categories', 'count_categories'
|
||||
),
|
||||
|
|
|
@ -405,8 +405,11 @@ SELECT id
|
|||
}
|
||||
if (count($datas))
|
||||
{
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
mass_inserts(CADDIE_TABLE, array('element_id','user_id'), $datas);
|
||||
mass_inserts(
|
||||
CADDIE_TABLE,
|
||||
array('element_id','user_id'),
|
||||
$datas
|
||||
);
|
||||
}
|
||||
return count($datas);
|
||||
}
|
||||
|
@ -1726,8 +1729,6 @@ function ws_images_add($params, $service)
|
|||
$params['image_id'] = (int)$params['image_id'];
|
||||
if ($params['image_id'] > 0)
|
||||
{
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
|
||||
$query='
|
||||
SELECT *
|
||||
FROM '.IMAGES_TABLE.'
|
||||
|
@ -1884,8 +1885,6 @@ function ws_images_addSimple($params, $service)
|
|||
$params['image_id'] = (int)$params['image_id'];
|
||||
if ($params['image_id'] > 0)
|
||||
{
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
|
||||
$query='
|
||||
SELECT *
|
||||
FROM '.IMAGES_TABLE.'
|
||||
|
@ -1936,20 +1935,18 @@ SELECT *
|
|||
{
|
||||
$update['id'] = $image_id;
|
||||
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
mass_updates(
|
||||
single_update(
|
||||
IMAGES_TABLE,
|
||||
array(
|
||||
'primary' => array('id'),
|
||||
'update' => array_diff(array_keys($update), array('id'))
|
||||
),
|
||||
array($update)
|
||||
$update,
|
||||
array('id', $update['id'])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (isset($params['tags']) and !empty($params['tags']))
|
||||
{
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
|
||||
$tag_ids = array();
|
||||
if (is_array($params['tags']))
|
||||
{
|
||||
|
@ -2564,13 +2561,10 @@ SELECT *
|
|||
{
|
||||
$update['id'] = $params['image_id'];
|
||||
|
||||
mass_updates(
|
||||
single_update(
|
||||
IMAGES_TABLE,
|
||||
array(
|
||||
'primary' => array('id'),
|
||||
'update' => array_diff(array_keys($update), array('id'))
|
||||
),
|
||||
array($update)
|
||||
$update,
|
||||
array('id', $update['id'])
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2805,13 +2799,13 @@ SELECT
|
|||
);
|
||||
}
|
||||
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
mass_inserts(
|
||||
IMAGE_CATEGORY_TABLE,
|
||||
array_keys($inserts[0]),
|
||||
$inserts
|
||||
);
|
||||
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
update_category($new_cat_ids);
|
||||
}
|
||||
|
||||
|
@ -2860,17 +2854,12 @@ function ws_categories_setInfo($params, $service)
|
|||
|
||||
if ($perform_update)
|
||||
{
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
mass_updates(
|
||||
single_update(
|
||||
CATEGORIES_TABLE,
|
||||
array(
|
||||
'primary' => array('id'),
|
||||
'update' => array_diff(array_keys($update), array('id'))
|
||||
),
|
||||
array($update)
|
||||
$update,
|
||||
array('id', $update['id'])
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ws_categories_setRepresentative($params, $service)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue