aboutsummaryrefslogtreecommitdiffstats
path: root/admin/site_update.php
diff options
context:
space:
mode:
Diffstat (limited to 'admin/site_update.php')
-rw-r--r--admin/site_update.php205
1 files changed, 153 insertions, 52 deletions
diff --git a/admin/site_update.php b/admin/site_update.php
index 764aecab9..5bcaea12a 100644
--- a/admin/site_update.php
+++ b/admin/site_update.php
@@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
@@ -31,6 +31,12 @@ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
// +-----------------------------------------------------------------------+
// | Check Access and exit when user status is not ok |
// +-----------------------------------------------------------------------+
+
+if (!$conf['enable_synchronization'])
+{
+ die('synchronization is disabled');
+}
+
check_status(ACCESS_ADMINISTRATOR);
if (!is_numeric($_GET['site']))
@@ -193,7 +199,7 @@ SELECT id_uppercat, MAX(rank)+1 AS next_rank
// category directory, we need to include it in our array
if (isset($_POST['cat']))
{
- array_push($fs_fulldirs, $basedir);
+ $fs_fulldirs[] = $basedir;
}
// If $_POST['subcats-included'] != 1 ("Search in sub-albums" is unchecked)
// $db_fulldirs doesn't include any subdirectories and $fs_fulldirs does
@@ -247,19 +253,17 @@ SELECT id_uppercat, MAX(rank)+1 AS next_rank
$insert['global_rank'] = $insert['rank'];
}
- array_push($inserts, $insert);
- array_push(
- $infos,
- array(
+ $inserts[] = $insert;
+ $infos[] = array(
'path' => $fulldir,
- 'info' => l10n('added')
- )
- );
+ 'info' => l10n('added'),
+ );
// add the new category to $db_categories and $db_fulldirs array
$db_categories[$insert{'id'}] =
array(
'id' => $insert['id'],
+ 'parent' => (isset($parent)) ? $parent : Null,
'status' => $insert['status'],
'visible' => $insert['visible'],
'uppercats' => $insert['uppercats'],
@@ -270,12 +274,9 @@ SELECT id_uppercat, MAX(rank)+1 AS next_rank
}
else
{
- array_push(
- $errors,
- array(
- 'path' => $fulldir,
- 'type' => 'PWG-UPDATE-1'
- )
+ $errors[] = array(
+ 'path' => $fulldir,
+ 'type' => 'PWG-UPDATE-1'
);
}
}
@@ -292,30 +293,140 @@ SELECT id_uppercat, MAX(rank)+1 AS next_rank
// add default permissions to categories
$category_ids = array();
+ $category_up = array();
foreach ($inserts as $category)
{
$category_ids[] = $category['id'];
+ if (!empty($category['id_uppercat']))
+ {
+ $category_up[] = $category['id_uppercat'];
+ }
+ }
+ $category_up=implode(',',array_unique($category_up));
+ if ($conf['inheritance_by_default'])
+ {
+ $query = '
+ SELECT *
+ FROM '.GROUP_ACCESS_TABLE.'
+ WHERE cat_id IN ('.$category_up.')
+ ;';
+ $result = pwg_query($query);
+ if (!empty($result))
+ {
+ $granted_grps = array();
+ while ($row = pwg_db_fetch_assoc($result))
+ {
+ if (!isset($granted_grps[$row['cat_id']]))
+ {
+ $granted_grps[$row['cat_id']]=array();
+ }
+ // TODO: explanaition
+ array_push(
+ $granted_grps,
+ array(
+ $row['cat_id'] => array_push($granted_grps[$row['cat_id']],$row['group_id'])
+ )
+ );
+ }
+ }
+ $query = '
+ SELECT *
+ FROM '.USER_ACCESS_TABLE.'
+ WHERE cat_id IN ('.$category_up.')
+ ;';
+ $result = pwg_query($query);
+ if (!empty($result))
+ {
+ $granted_users = array();
+ while ($row = pwg_db_fetch_assoc($result))
+ {
+ if (!isset($granted_users[$row['cat_id']]))
+ {
+ $granted_users[$row['cat_id']]=array();
+ }
+ // TODO: explanaition
+ array_push(
+ $granted_users,
+ array(
+ $row['cat_id'] => array_push($granted_users[$row['cat_id']],$row['user_id'])
+ )
+ );
+ }
+ }
+ $insert_granted_users=array();
+ $insert_granted_grps=array();
+ foreach ($category_ids as $ids)
+ {
+ $parent_id=$db_categories[$ids]['parent'];
+ while (in_array($parent_id, $category_ids))
+ {
+ $parent_id= $db_categories[$parent_id]['parent'];
+ }
+ if ($db_categories[$ids]['status']=='private' and !is_null($parent_id))
+ {
+ if (isset($granted_grps[$parent_id]))
+ {
+ foreach ($granted_grps[$parent_id] as $granted_grp)
+ {
+ $insert_granted_grps[] = array(
+ 'group_id' => $granted_grp,
+ 'cat_id' => $ids
+ );
+ }
+ }
+ if (isset($granted_users[$parent_id]))
+ {
+ foreach ($granted_users[$parent_id] as $granted_user)
+ {
+ $insert_granted_users[] = array(
+ 'user_id' => $granted_user,
+ 'cat_id' => $ids
+ );
+ }
+ }
+ foreach (get_admins() as $granted_user)
+ {
+ $insert_granted_users[] = array(
+ 'user_id' => $granted_user,
+ 'cat_id' => $ids
+ );
+ }
+ }
+ }
+ mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $insert_granted_grps);
+ $insert_granted_users=array_unique($insert_granted_users, SORT_REGULAR);
+ mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $insert_granted_users);
+ }
+ else
+ {
+ add_permission_on_category($category_ids, get_admins());
}
- add_permission_on_category($category_ids, get_admins());
}
$counts['new_categories'] = count($inserts);
}
// to delete categories
- $to_delete = array(); $to_delete_derivative_dirs = array();
+ $to_delete = array();
+ $to_delete_derivative_dirs = array();
+
foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir)
{
- array_push($to_delete, $db_fulldirs[$fulldir]);
+ $to_delete[] = $db_fulldirs[$fulldir];
unset($db_fulldirs[$fulldir]);
- array_push($infos, array('path' => $fulldir,
- 'info' => l10n('deleted')));
+
+ $infos[] = array(
+ 'path' => $fulldir,
+ 'info' => l10n('deleted')
+ );
+
if (substr_compare($fulldir, '../', 0, 3)==0)
{
$fulldir = substr($fulldir, 3);
}
$to_delete_derivative_dirs[] = PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$fulldir;
}
+
if (count($to_delete) > 0)
{
if (!$simulate)
@@ -388,12 +499,9 @@ SELECT id, path
$filename = basename($path);
if (!preg_match($conf['sync_chars_regex'], $filename))
{
- array_push(
- $errors,
- array(
- 'path' => $path,
- 'type' => 'PWG-UPDATE-1'
- )
+ $errors[] = array(
+ 'path' => $path,
+ 'type' => 'PWG-UPDATE-1'
);
continue;
@@ -415,25 +523,16 @@ SELECT id, path
$insert['level'] = $_POST['privacy_level'];
}
- array_push(
- $inserts,
- $insert
- );
+ $inserts[] = $insert;
- array_push(
- $insert_links,
- array(
- 'image_id' => $insert['id'],
- 'category_id' => $insert['storage_category_id'],
- )
+ $insert_links[] = array(
+ 'image_id' => $insert['id'],
+ 'category_id' => $insert['storage_category_id'],
);
- array_push(
- $infos,
- array(
- 'path' => $insert['path'],
- 'info' => l10n('added')
- )
+ $infos[] = array(
+ 'path' => $insert['path'],
+ 'info' => l10n('added')
);
$caddiables[] = $insert['id'];
@@ -470,9 +569,11 @@ SELECT id, path
$to_delete_elements = array();
foreach (array_diff($db_elements, array_keys($fs)) as $path)
{
- array_push($to_delete_elements, array_search($path, $db_elements));
- array_push($infos, array('path' => $path,
- 'info' => l10n('deleted')));
+ $to_delete_elements[] = array_search($path, $db_elements);
+ $infos[] = array(
+ 'path' => $path,
+ 'info' => l10n('deleted')
+ );
}
if (count($to_delete_elements) > 0)
{
@@ -541,7 +642,7 @@ if (isset($_POST['submit'])
}
$data['id']=$id;
- array_push($datas, $data);
+ $datas[] = $data;
} // end foreach file
$counts['upd_elements'] = count($datas);
@@ -622,7 +723,7 @@ if (isset($_POST['submit']) and isset($_POST['sync_meta'])
{
$data['date_metadata_update'] = CURRENT_DATE;
$data['id']=$id;
- array_push($datas, $data);
+ $datas[] = $data;
foreach (array('keywords', 'tags') as $key)
{
@@ -635,17 +736,17 @@ if (isset($_POST['submit']) and isset($_POST['sync_meta'])
foreach (explode(',', $data[$key]) as $tag_name)
{
- array_push(
- $tags_of[$id],
- tag_id_from_tag_name($tag_name)
- );
+ $tags_of[$id][] = tag_id_from_tag_name($tag_name);
}
}
}
}
else
{
- array_push($errors, array('path' => $element_infos['path'], 'type' => 'PWG-ERROR-NO-FS'));
+ $errors[] = array(
+ 'path' => $element_infos['path'],
+ 'type' => 'PWG-ERROR-NO-FS'
+ );
}
}