Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Make sure to make the repository slugs unique - should be part of a f…
Browse files Browse the repository at this point in the history
…utur upgrade script

Hack shareCenter to display all actions in admin driver
Sort plugins by name in actions lists
  • Loading branch information
cdujeu committed May 17, 2014
1 parent 7a19a9e commit 8ff4fc3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
Expand Up @@ -133,6 +133,7 @@ public function listAllActions($action, $httpVars, $fileVars)
$actions[$pId][$actionName] = array( "action" => $actionName , "label" => $messId);

}
ksort($actions, SORT_STRING);
foreach ($actions as $actPid => $actionGroup) {
ksort($actionGroup, SORT_STRING);
$actions[$actPid] = array();
Expand Down
4 changes: 3 additions & 1 deletion core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -74,7 +74,9 @@ protected function parseSpecificContributions(&$contribNode)
}
}
$repo = ConfService::getRepository();
if(!is_a($repo->driverInstance, "AjxpWrapperProvider")){
// Hacky but necessary to edit roles...
if(!is_a($repo->driverInstance, "AjxpWrapperProvider")
&& !(isset($_GET["get_action"]) && $_GET["get_action"]=="list_all_plugins_actions")){
$disableSharing = true;
}
if ($disableSharing) {
Expand Down
52 changes: 38 additions & 14 deletions core/src/plugins/conf.sql/class.sqlConfDriver.php
Expand Up @@ -327,6 +327,30 @@ public function getRepositoryByAlias($repositorySlug)
return null;
}

/**
* @param String $slug
* @param String|null $repositoryId
* @return String mixed
*/
protected function uniquifySlug($slug, $repositoryId = null){

if($repositoryId != null){
$res = dibi::query("SELECT [slug],[uuid] FROM [ajxp_repo] WHERE [uuid] != %s AND [slug] LIKE '".$slug."%'", $repositoryId);
}else{
$res = dibi::query("SELECT [slug],[uuid] FROM [ajxp_repo] WHERE [slug] LIKE '".$slug."%'");
}
$existingSlugs = $res->fetchPairs();
if(!count($existingSlugs)) return $slug;
$index = 1;
$base = $slug;
$slug = $base."-".$index;
while(isSet($existingSlugs[$slug])){
$index++;
$slug = $base."-".$index;
}

return $slug;
}

/**
* Store a newly created repository
Expand All @@ -338,12 +362,20 @@ public function getRepositoryByAlias($repositorySlug)
public function saveRepository($repositoryObject, $update = false)
{
try {
$repository_array = $this->repoToArray($repositoryObject);
$options = $repository_array['options'];
if($repositoryObject->hasContentFilter()){
$options["content_filter"] = $repositoryObject->getContentFilter();
}
unset($repository_array['options']);
if($update){
$repositoryObject->setSlug($this->uniquifySlug(
$repositoryObject->getSlug(),
$repositoryObject->getUniqueId()
));
}else{
$repositoryObject->setSlug($this->uniquifySlug($repositoryObject->getSlug()));
}
$repository_array = $this->repoToArray($repositoryObject);
$options = $repository_array['options'];
if($repositoryObject->hasContentFilter()){
$options["content_filter"] = $repositoryObject->getContentFilter();
}
unset($repository_array['options']);
if (!$update) {
dibi::query('INSERT INTO [ajxp_repo]', $repository_array);

Expand All @@ -353,14 +385,6 @@ public function saveRepository($repositoryObject, $update = false)
}
dibi::query('INSERT INTO [ajxp_repo_options] ([uuid],[name],[val]) VALUES (%s,%s,%bin)', $repositoryObject->getUniqueId(), $k,$v);
}
/*
//set maximum rights to the repositorie's creator jcg
$user_right['login'] = $_SESSION["AJXP_USER"]->id;
$user_right['repo_uuid'] = $repository_array['uuid'];
$user_right['rights'] = 'rw';
dibi::query('INSERT INTO [ajxp_user_rights]', $user_right);
$userid=$_SESSION["AJXP_USER"]->id;
*/

} else {
dibi::query('DELETE FROM [ajxp_repo] WHERE [uuid] = %s',$repositoryObject->getUniqueId());
Expand Down

0 comments on commit 8ff4fc3

Please sign in to comment.