OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
101
app/Domain/Entityrelations/Repositories/Entityrelations.php
Normal file
101
app/Domain/Entityrelations/Repositories/Entityrelations.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Entityrelations\Repositories;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Leantime\Core\Db\Db as DbCore;
|
||||
|
||||
class Entityrelations
|
||||
{
|
||||
private ConnectionInterface $db;
|
||||
|
||||
public array $applications = [
|
||||
'general' => 'General',
|
||||
];
|
||||
|
||||
/**
|
||||
* __construct - neu db connection
|
||||
*/
|
||||
public function __construct(DbCore $db)
|
||||
{
|
||||
$this->db = $db->getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|mixed
|
||||
*/
|
||||
public function getSetting(string $type): mixed
|
||||
{
|
||||
if ($this->checkIfInstalled() === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->db->table('zp_settings')
|
||||
->where('key', $type)
|
||||
->limit(1)
|
||||
->first();
|
||||
|
||||
if ($result !== null && isset($result->value)) {
|
||||
return $result->value;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (Exception $e) {
|
||||
report($e);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function saveSetting(string $type, string $value): bool
|
||||
{
|
||||
if ($this->checkIfInstalled() === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->db->table('zp_settings')
|
||||
->updateOrInsert(
|
||||
['key' => $type],
|
||||
['value' => $value]
|
||||
);
|
||||
}
|
||||
|
||||
public function deleteSetting(string $type): void
|
||||
{
|
||||
$this->db->table('zp_settings')
|
||||
->where('key', $type)
|
||||
->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* checkIfInstalled checks if zp user table exists (and assumes that leantime is installed)
|
||||
*/
|
||||
public function checkIfInstalled(): bool
|
||||
{
|
||||
if (session()->exists('isInstalled') && session('isInstalled')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (! Schema::hasTable('zp_user')) {
|
||||
session(['isInstalled' => false]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->db->table('zp_user')->count();
|
||||
|
||||
session(['isInstalled' => true]);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
report($e);
|
||||
session(['isInstalled' => false]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
app/Domain/Entityrelations/Services/Entityrelations.php
Normal file
36
app/Domain/Entityrelations/Services/Entityrelations.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Entityrelations\Services;
|
||||
|
||||
use Leantime\Domain\Setting\Repositories\Setting;
|
||||
|
||||
class Entityrelations
|
||||
{
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param Setting $settingsRepo The settings repository.
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
private Setting $settingsRepo
|
||||
) {}
|
||||
|
||||
public function saveRelationship($entityA, $entityAType, $relationship, $entityB, $entityBType, string $meta = ''): mixed
|
||||
{
|
||||
// FIXME(phpstan-l2): this method is broken. Setting::saveSetting() is (string $type,
|
||||
// mixed $value) — only the first two args were ever persisted; $relationship/$entityB/
|
||||
// $entityBType/$meta were silently dropped by PHP. The injected EntityrelationRepository
|
||||
// ($entityRelationshipsRepo) also has no matching 6-arg method. Trimmed to preserve
|
||||
// current runtime behavior; the relationship-storage design needs to be rebuilt.
|
||||
return $this->settingsRepo->saveSetting($entityA, $entityAType);
|
||||
}
|
||||
|
||||
public function getRelationshipByEntity(string $entitySide, int $entity, string $entityType, string $relationship): mixed
|
||||
{
|
||||
// FIXME(phpstan-l2): broken counterpart of saveRelationship() — Setting::getSetting() is
|
||||
// (string $type, mixed $default = false); the extra args were silently dropped. Trimmed
|
||||
// to preserve current runtime behavior. Needs a real entity-relationship store.
|
||||
return $this->settingsRepo->getSetting($entitySide, $entity);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user