Upgrade to Laravel 11, begining of enabling network join functionality, removed QueryCacheable
This commit is contained in:
@@ -36,7 +36,7 @@ class DomainController extends Controller
|
||||
public function add_edit(DomainRequest $request,Domain $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
foreach (['name','dnsdomain','active','public','homepage','notes','flatten'] as $key)
|
||||
foreach (['name','dnsdomain','active','public','homepage','notes','flatten','accept_app'] as $key)
|
||||
$o->{$key} = $request->post($key);
|
||||
|
||||
$o->save();
|
||||
|
@@ -27,6 +27,7 @@ class DomainRequest extends FormRequest
|
||||
'dnsdomain' => 'nullable|regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i|unique:domains,dnsdomain,'.($o->exists ? $o->id : NULL),
|
||||
'active' => 'required|boolean',
|
||||
'public' => 'required|boolean',
|
||||
'accept_app' => 'required|boolean',
|
||||
'flatten' => 'nullable|boolean',
|
||||
];
|
||||
}
|
||||
|
@@ -12,11 +12,11 @@ use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Casts\CompressedString;
|
||||
use App\Traits\{QueryCacheableConfig,ScopeActive};
|
||||
use App\Traits\ScopeActive;
|
||||
|
||||
class Domain extends Model
|
||||
{
|
||||
use HasFactory,ScopeActive,QueryCacheableConfig;
|
||||
use HasFactory,ScopeActive;
|
||||
|
||||
private const CACHE_TIME = 3600;
|
||||
private const STATS_MONTHS = 6;
|
||||
@@ -62,6 +62,15 @@ class Domain extends Model
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getCanAcceptAppAttribute(): bool
|
||||
{
|
||||
return our_address($this)->count()
|
||||
&& $this->active
|
||||
&& $this->accept_app
|
||||
&& Auth::id()
|
||||
&& $this->userHasSystemsNotInNet(Auth::user())->count();
|
||||
}
|
||||
|
||||
public function getHomePageAttribute(?string $value): string
|
||||
{
|
||||
//0xFD2FB528
|
||||
@@ -78,8 +87,7 @@ class Domain extends Model
|
||||
->whenRaw("datetime >= '?'",$dt->subMonth()->format('Y-m-d'))->thenRaw("'month'")
|
||||
->elseRaw("'all'");
|
||||
|
||||
return Echoarea::cacheFor(self::CACHE_TIME)
|
||||
->select(['echoareas.id','name','description','active',DB::raw('count(echomails.id) AS count'),DB::raw('max(datetime) as last_message')])
|
||||
return Echoarea::select(['echoareas.id','name','description','active',DB::raw('count(echomails.id) AS count'),DB::raw('max(datetime) as last_message')])
|
||||
->selectRaw($case->toRaw().' AS stats')
|
||||
->join('echomails',['echomails.echoarea_id'=>'echoareas.id'],NULL,NULL,'left outer')
|
||||
->where('domain_id',$this->id)
|
||||
@@ -124,4 +132,23 @@ class Domain extends Model
|
||||
{
|
||||
return our_address($this)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out which of the users systems are not in this domain
|
||||
*
|
||||
* @param User $o
|
||||
* @return Collection
|
||||
*/
|
||||
public function userHasSystemsNotInNet(User $o): Collection
|
||||
{
|
||||
$o->load('systems.akas.zone');
|
||||
|
||||
$result = collect();
|
||||
foreach ($o->systems->filter(function($item) { return $item->active; }) as $so) {
|
||||
if (! $so->akas->pluck('zone')->unique('domain_id')->pluck('domain_id')->contains($this->id))
|
||||
$result->push($so);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
@@ -4,13 +4,12 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
use App\Casts\CollectionOrNull;
|
||||
|
||||
class Dynamic extends Model
|
||||
{
|
||||
use SoftDeletes,QueryCacheable;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $casts = [
|
||||
'arguments' => CollectionOrNull::class,
|
||||
|
@@ -6,7 +6,6 @@ use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
use App\Traits\{AreaSecurity,ScopeActive};
|
||||
|
||||
@@ -42,7 +41,7 @@ use App\Traits\{AreaSecurity,ScopeActive};
|
||||
*/
|
||||
class Echoarea extends Model
|
||||
{
|
||||
use SoftDeletes,ScopeActive,QueryCacheable,AreaSecurity;
|
||||
use SoftDeletes,ScopeActive,AreaSecurity;
|
||||
|
||||
private const CACHE_TIME = 3600;
|
||||
|
||||
@@ -72,8 +71,7 @@ class Echoarea extends Model
|
||||
|
||||
public function messages_count(int $period=NULL): int
|
||||
{
|
||||
$eo = Echomail::cacheFor(self::CACHE_TIME)
|
||||
->where('echoarea_id',$this->id);
|
||||
$eo = Echomail::where('echoarea_id',$this->id);
|
||||
|
||||
$dt = Carbon::now()->startOfday();
|
||||
|
||||
|
@@ -8,7 +8,6 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
use App\Casts\{CollectionOrNull,CompressedString};
|
||||
use App\Classes\FTN\Message;
|
||||
@@ -17,7 +16,7 @@ use App\Traits\{EncodeUTF8,MsgID,ParseAddresses};
|
||||
|
||||
final class Echomail extends Model implements Packet
|
||||
{
|
||||
use SoftDeletes,EncodeUTF8,MsgID,QueryCacheable,ParseAddresses;
|
||||
use SoftDeletes,EncodeUTF8,MsgID,ParseAddresses;
|
||||
|
||||
private const LOGKEY = 'ME-';
|
||||
private Collection $set_seenby;
|
||||
|
@@ -10,14 +10,13 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
use App\Casts\{CollectionOrNull,CompressedString};
|
||||
use App\Traits\EncodeUTF8;
|
||||
|
||||
class File extends Model
|
||||
{
|
||||
use SoftDeletes,EncodeUTF8,QueryCacheable;
|
||||
use SoftDeletes,EncodeUTF8;
|
||||
|
||||
private const LOGKEY = 'MF-';
|
||||
private bool $no_export = FALSE;
|
||||
|
@@ -75,27 +75,21 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
|
||||
/* GENERAL METHODS */
|
||||
|
||||
public function addresses(): Collection
|
||||
public function addresses(Domain $o=NULL): Collection
|
||||
{
|
||||
return Address::select('addresses.*')
|
||||
->join('systems',['systems.id'=>'addresses.system_id'])
|
||||
->join('system_user',['system_user.system_id'=>'systems.id'])
|
||||
->when(! is_null($o),function($query) use ($o) {
|
||||
return $query
|
||||
->join('zones',['zones.id'=>'addresses.zone_id'])
|
||||
->where('zones.domain_id',$o->id);
|
||||
})
|
||||
->where('system_user.user_id',$this->id)
|
||||
->with(['zone.domain'])
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* See if the user is already a member of the chosen network
|
||||
*
|
||||
* @param Domain $o
|
||||
* @return bool
|
||||
*/
|
||||
public function isMember(Domain $o): bool
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this user a ZC of a domain?
|
||||
*
|
||||
@@ -128,6 +122,8 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
*/
|
||||
public function zc(): Collection
|
||||
{
|
||||
$this->load('systems.addresses');
|
||||
|
||||
return $this->systems->pluck('addresses')->flatten()->where('role',Address::NODE_ZC);
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Traits\{QueryCacheableConfig,ScopeActive};
|
||||
use App\Traits\ScopeActive;
|
||||
|
||||
class Zone extends Model
|
||||
{
|
||||
|
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Set defaults of QueryCacheable
|
||||
*/
|
||||
namespace App\Traits;
|
||||
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
trait QueryCacheableConfig
|
||||
{
|
||||
use QueryCacheable;
|
||||
|
||||
public $cacheFor = 900; // cache time, in seconds
|
||||
protected static $flushCacheOnUpdate = TRUE;
|
||||
public $cacheDriver = 'memcached';
|
||||
}
|
Reference in New Issue
Block a user