-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87a3fe5
commit adbb131
Showing
1 changed file
with
16 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,15 @@ | |
|
||
namespace Bex\Niceaccess; | ||
|
||
use Bex\Tools\GroupTools; | ||
use Bex\Tools\Group\GroupTools; | ||
use Bex\Tools\ValueNotFoundException; | ||
use Bitrix\Main\ArgumentNullException; | ||
use Bitrix\Main\IO\File; | ||
use Bitrix\Main\IO\InvalidPathException; | ||
|
||
/** | ||
* Implements replacement of user group id's by \Bex\Tools method which returns user group id by symbol code | ||
* in .access.php files. File .access.php will not depend on DB user group id after that | ||
* in .access.php files. File .access.php will not depend on DB user group id after that. | ||
* | ||
* @author Nik Samokhvalov <[email protected]> | ||
*/ | ||
|
@@ -48,12 +49,11 @@ public function __construct($path) | |
} | ||
|
||
/** | ||
* Resave file .access.php, with usage symbol of the codes users groups instead id's | ||
* Converting content from .access.php file, with usage symbol of the codes users groups instead id's. | ||
* | ||
* @param string $content | ||
* | ||
* @return bool | ||
* @throws ArgumentNullException | ||
*/ | ||
public function convertContent(&$content) | ||
{ | ||
|
@@ -63,17 +63,25 @@ public function convertContent(&$content) | |
} | ||
elseif (empty($content)) | ||
{ | ||
throw new ArgumentNullException('content'); | ||
return false; | ||
} | ||
|
||
$content = preg_replace_callback('/(PERM\[.+\]\[)(\"G?[0-9]+\")(\])/', function ($matches) { | ||
$matches[2] = trim($matches[2], "\""); | ||
$groupId = str_replace('G', '', $matches[2], $addG); | ||
|
||
try | ||
{ | ||
$groupCode = GroupTools::findById($groupId)->code(); | ||
} | ||
catch (ValueNotFoundException $e) | ||
{ | ||
return $matches[0]; | ||
} | ||
|
||
// @todo Если символьный код не установлен? | ||
$groupCode = GroupTools::findById($groupId)->code(); | ||
$value = ($addG ? "'G'." : '') . '\Bex\Tools\Group\GroupTools::find(\'' . $groupCode . '\', true)->id()'; | ||
|
||
return $matches[1] . ($addG ? "'G'." : '') . "\Bex\Tools\Group\GroupTools::find('{$groupCode}')->id()" . $matches[3]; | ||
return $matches[1] . $value . $matches[3]; | ||
}, $content); | ||
|
||
return true; | ||
|