68 lines
2.1 KiB
PHP
68 lines
2.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\Agency\Controller;
|
|
|
|
use OCP\IRequest;
|
|
use OCP\IUserSession;
|
|
use OCP\IGroupManager;
|
|
use OCP\IUserManager;
|
|
use OCP\IGroup;
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
class MigrateController extends Controller {
|
|
|
|
protected $userSession;
|
|
protected $request;
|
|
protected $connection;
|
|
protected $groupManager;
|
|
protected $userManager;
|
|
|
|
use Errors;
|
|
|
|
public function __construct(string $AppName, IRequest $request, IUserSession $userSession,IDBConnection $connection, IGroupManager $groupManager, IUserManager $userManager){
|
|
parent::__construct($AppName, $request);
|
|
$this->userSession = $userSession;
|
|
$this->request = $request;
|
|
$this->connection = $connection;
|
|
$this->groupManager = $groupManager;
|
|
$this->userManager = $userManager;
|
|
}
|
|
|
|
// Return an random Id-Ele for generating single IDs
|
|
public function generateRandomPassword($length = 50) {
|
|
$characters = '_=()?!-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
return $randomString;
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*/
|
|
public function startMigration(string $agencyid, string $mainurl) {
|
|
$json = file_get_contents($mainurl.$agencyid);
|
|
|
|
// Hier werden die Nutzer erstellt, anhand eines JSON-Arrays von der API (migrateAgency)
|
|
$ag_data = json_decode($json, true);
|
|
$feedbackstring = "Erstelle Nutzer: ";
|
|
foreach($ag_data as $ele){
|
|
|
|
$feedbackstring .= $ele['displayname'].", ";
|
|
|
|
if($this->userManager->userExists($ele['userid']) == false){
|
|
$tempuser = $this->userManager->createUser($ele['userid'], $this->generateRandomPassword());
|
|
$tempuser->setEmailAddress($ele['userid']);
|
|
}
|
|
|
|
}
|
|
return $feedbackstring;
|
|
}
|
|
} |