merge r17668 from branch 2.4 to trunk

bug 2733 fixed: when creating a sub-album in a private album with
pwg.categories.add, it is automatically private too.



git-svn-id: http://piwigo.org/svn/trunk@17669 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
plegall 2012-08-30 12:54:29 +00:00
parent 62452b90ce
commit 6beee17904
3 changed files with 79 additions and 71 deletions

View file

@ -1196,7 +1196,7 @@ DELETE FROM '.$table.'
* @param int parent category id * @param int parent category id
* @return array with ('info' and 'id') or ('error') key * @return array with ('info' and 'id') or ('error') key
*/ */
function create_virtual_category($category_name, $parent_id=null) function create_virtual_category($category_name, $parent_id=null, $options=array())
{ {
global $conf, $user; global $conf, $user;
@ -1206,15 +1206,53 @@ function create_virtual_category($category_name, $parent_id=null)
return array('error' => l10n('The name of an album must not be empty')); return array('error' => l10n('The name of an album must not be empty'));
} }
$parent_id = !empty($parent_id) ? $parent_id : 'NULL';
$insert = array( $insert = array(
'name' => $category_name, 'name' => $category_name,
'rank' => 0, 'rank' => 0,
'commentable' => boolean_to_string($conf['newcat_default_commentable']), 'global_rank' => 0,
); );
if ($parent_id != 'NULL') // is the album commentable?
if (isset($options['commentable']) and is_bool($options['commentable']))
{
$insert['commentable'] = $options['commentable'];
}
else
{
$insert['commentable'] = $conf['newcat_default_commentable'];
}
$insert['commentable'] = boolean_to_string($insert['commentable']);
// is the album temporarily locked? (only visible by administrators,
// whatever permissions) (may be overwritten if parent album is not
// visible)
if (isset($options['visible']) and is_bool($options['visible']))
{
$insert['visible'] = $options['visible'];
}
else
{
$insert['visible'] = $conf['newcat_default_visible'];
}
$insert['visible'] = boolean_to_string($insert['visible']);
// is the album private? (may be overwritten if parent album is private)
if (isset($options['status']) and 'private' == $options['status'])
{
$insert['status'] = 'private';
}
else
{
$insert['status'] = $conf['newcat_default_status'];
}
// any description for this album?
if (isset($options['comment']))
{
$insert['comment'] = strip_tags($options['comment']);
}
if (!empty($parent_id) and is_numeric($parent_id))
{ {
$query = ' $query = '
SELECT id, uppercats, global_rank, visible, status SELECT id, uppercats, global_rank, visible, status
@ -1233,10 +1271,6 @@ SELECT id, uppercats, global_rank, visible, status
{ {
$insert['visible'] = 'false'; $insert['visible'] = 'false';
} }
else
{
$insert['visible'] = boolean_to_string($conf['newcat_default_visible']);
}
// at creation, must a category be public or private ? Warning : if the // at creation, must a category be public or private ? Warning : if the
// parent category is private, the category is automatically create // parent category is private, the category is automatically create
@ -1245,40 +1279,23 @@ SELECT id, uppercats, global_rank, visible, status
{ {
$insert['status'] = 'private'; $insert['status'] = 'private';
} }
else
{ $uppercats_prefix = $parent['uppercats'].',';
$insert['status'] = $conf['newcat_default_status'];
}
} }
else else
{ {
$insert['visible'] = boolean_to_string($conf['newcat_default_visible']); $uppercats_prefix = '';
$insert['status'] = $conf['newcat_default_status'];
$insert['global_rank'] = $insert['rank'];
} }
// we have then to add the virtual category // we have then to add the virtual category
mass_inserts( single_insert(CATEGORIES_TABLE, $insert);
CATEGORIES_TABLE,
array(
'site_id', 'name', 'id_uppercat', 'rank', 'commentable',
'visible', 'status', 'global_rank',
),
array($insert)
);
$inserted_id = pwg_db_insert_id(CATEGORIES_TABLE); $inserted_id = pwg_db_insert_id(CATEGORIES_TABLE);
$query = ' single_update(
UPDATE CATEGORIES_TABLE,
'.CATEGORIES_TABLE.' array('uppercats' => $uppercats_prefix.$inserted_id),
SET uppercats = \''. array('id' => $inserted_id)
(isset($parent) ? $parent{'uppercats'}.',' : ''). );
$inserted_id.
'\'
WHERE id = '.$inserted_id.'
;';
pwg_query($query);
update_global_rank(); update_global_rank();

View file

@ -2302,9 +2302,32 @@ function ws_categories_add($params, &$service)
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
$options = array();
if (!empty($params['status']) and in_array($params['status'], array('private','public')))
{
$options['status'] = $params['status'];
}
if (!empty($params['visible']) and in_array($params['visible'], array('true','false')))
{
$options['visible'] = get_boolean($params['visible']);
}
if (!empty($params['commentable']) and in_array($params['commentable'], array('true','false')) )
{
$options['commentable'] = get_boolean($params['commentable']);
}
if (!empty($params['comment']))
{
$options['comment'] = $params['comment'];
}
$creation_output = create_virtual_category( $creation_output = create_virtual_category(
$params['name'], $params['name'],
$params['parent'] $params['parent'],
$options
); );
if (isset($creation_output['error'])) if (isset($creation_output['error']))
@ -2312,38 +2335,6 @@ function ws_categories_add($params, &$service)
return new PwgError(500, $creation_output['error']); return new PwgError(500, $creation_output['error']);
} }
$updates = array();
if ( !empty($params['status']) and in_array($params['status'], array('private','public')) )
{
$updates['status'] = $params['status'];
}
if ( !empty($params['visible']) and in_array($params['visible'], array('true','false')) )
{
$updates['visible'] = $params['visible'];
}
if ( !empty($params['commentable']) and in_array($params['commentable'], array('true','false')) )
{
$updates['commentable'] = $params['commentable'];
}
if ( !empty($params['comment']) )
{
$updates['comment'] = strip_tags($params['comment']);
}
if (!empty($updates))
{
single_update(
CATEGORIES_TABLE,
$updates,
array('id'=>$creation_output['id'])
);
}
if ( isset($updates['status']) and 'private' == $updates['status'] )
{
add_permission_on_category($creation_output['id'], get_admins());
}
invalidate_user_cache(); invalidate_user_cache();
return $creation_output; return $creation_output;

4
ws.php
View file

@ -309,8 +309,8 @@ function ws_addDefaultMethods( $arr )
'name' => array(), 'name' => array(),
'parent' => array('default' => null), 'parent' => array('default' => null),
'comment' => array('default' => null), 'comment' => array('default' => null),
'visible' => array('default' => boolean_to_string($conf['newcat_default_visible'])), 'visible' => array('default' => null),
'status' => array('default' => $conf['newcat_default_status']), 'status' => array('default' => null),
'commentable' => array('default' => 'true'), 'commentable' => array('default' => 'true'),
), ),
'administration method only' 'administration method only'