TASK-221 Change the AUTH_SOURCE_DATA field from PHP-serialized format to a JSON-formatted string
This commit is contained in:
@@ -5,13 +5,94 @@ namespace ProcessMaker\Model;
|
||||
use App\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use \Exception;
|
||||
use \G;
|
||||
|
||||
class RbacAuthenticationSource extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = "RBAC_AUTHENTICATION_SOURCE";
|
||||
public $incrementing = false;
|
||||
protected $table = 'RBAC_AUTHENTICATION_SOURCE';
|
||||
protected $fillable = [
|
||||
'AUTH_SOURCE_UID',
|
||||
'AUTH_SOURCE_NAME',
|
||||
'AUTH_SOURCE_PROVIDER',
|
||||
'AUTH_SOURCE_SERVER_NAME',
|
||||
'AUTH_SOURCE_PORT',
|
||||
'AUTH_SOURCE_ENABLED_TLS',
|
||||
'AUTH_SOURCE_VERSION',
|
||||
'AUTH_SOURCE_BASE_DN',
|
||||
'AUTH_ANONYMOUS',
|
||||
'AUTH_SOURCE_SEARCH_USER',
|
||||
'AUTH_SOURCE_PASSWORD',
|
||||
'AUTH_SOURCE_ATTRIBUTES',
|
||||
'AUTH_SOURCE_OBJECT_CLASSES',
|
||||
'AUTH_SOURCE_DATA'
|
||||
];
|
||||
public $timestamps = false;
|
||||
|
||||
public function show($filters = array())
|
||||
{
|
||||
try {
|
||||
$query = static::query();
|
||||
|
||||
if (is_array($filters['fields'])) {
|
||||
$query->select($filters['fields']);
|
||||
}
|
||||
|
||||
if (is_array($filters['conditions'])) {
|
||||
if (!empty($filters['conditions']['text'])) {
|
||||
$query->where('AUTH_SOURCE_NAME', 'like', '%' . $filters['conditions']['text'] . '%');
|
||||
unset($filters['conditions']['text']);
|
||||
}
|
||||
$query->where($filters['conditions']);
|
||||
}
|
||||
|
||||
$total = $query->count();
|
||||
|
||||
if (is_array($filters['start']) || is_array($filters['limit'])) {
|
||||
$start = $filters['start'] ?? 0;
|
||||
$limit = $filters['limit'] ?? 25;
|
||||
$query->offset($start)->limit($limit);
|
||||
}
|
||||
|
||||
if (is_array($filters['orderBy'])) {
|
||||
$query->orderBy($filters['orderBy'][0], $filters['orderBy'][1] ?? 'asc');
|
||||
}
|
||||
|
||||
$data =$query->get()->toArray();
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $data
|
||||
];
|
||||
return $result;
|
||||
} catch (Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
public static function remove($conditions)
|
||||
{
|
||||
try {
|
||||
$query = static::query();
|
||||
$query->where($conditions);
|
||||
$deleteRows = $query->delete();
|
||||
return ['deleteRows' => $deleteRows];
|
||||
} catch (Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static function saveData($authSourceData)
|
||||
{
|
||||
try {
|
||||
if (empty($authSourceData['AUTH_SOURCE_UID'])) {
|
||||
$authSourceData['AUTH_SOURCE_UID'] = G::generateUniqueID();
|
||||
$responseSave = self::create($authSourceData);
|
||||
} else {
|
||||
$responseSave = self::where('AUTH_SOURCE_UID', $authSourceData['AUTH_SOURCE_UID'])
|
||||
->update($authSourceData);
|
||||
}
|
||||
return $responseSave;
|
||||
} catch (Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user