Skip to content

Commit 5debb35

Browse files
Merge pull request #130 from dimitriBouteille/develop
📦 Release 4.3.0
2 parents 05cba04 + 7cc23de commit 5debb35

File tree

12 files changed

+415
-4
lines changed

12 files changed

+415
-4
lines changed

.github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949

5050
services:
5151
mysql:
52-
image: mysql:9.1
52+
image: mysql:9.2
5353
env:
5454
MYSQL_ALLOW_EMPTY_PASSWORD: false
5555
ports:
@@ -106,7 +106,7 @@ jobs:
106106
runs-on: ubuntu-latest
107107
steps:
108108
- name: Close parallel build
109-
uses: coverallsapp/github-action@v1
109+
uses: coverallsapp/github-action@v2
110110
with:
111111
parallel-finished: true
112112
carryforward: "wp-test-1,wp-test-2,wp-test-3,wp-test-4,wp-test-5,wp-test-6,unit"

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The ORM is based on [Eloquent ORM](https://laravel.com/docs/eloquent) and uses t
1919
- ✅ Based on core WordPress database connection (`wpdb` class), no configuration required !
2020
- ✅ Custom functions to filter models with meta
2121
- ✅ Meta casting (e.g. [Attribute Casting](https://laravel.com/docs/eloquent-mutators#attribute-casting))
22+
- ✅ Multisite support
2223
- ❤️ Easy integration of a custom post and comment type
2324
- ❤️ Easy model creation for projects with custom tables
2425
- ❤️ All the features available in Eloquent, are usable with this library !

src/Models/Meta/UserMeta.php

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class UserMeta extends AbstractMeta
2929
*/
3030
protected $table = 'usermeta';
3131

32+
/**
33+
* @inheritdoc
34+
*/
35+
protected bool $useBasePrefix = true;
36+
3237
/**
3338
* @return HasOne
3439
*/

src/Models/Multisite/Blog.php

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Copyright © Dimitri BOUTEILLE (https://github.com/dimitriBouteille)
4+
* See LICENSE.txt for license details.
5+
*
6+
* Author: Dimitri BOUTEILLE <[email protected]>
7+
*/
8+
9+
namespace Dbout\WpOrm\Models\Multisite;
10+
11+
use Carbon\Carbon;
12+
use Dbout\WpOrm\Orm\AbstractModel;
13+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
14+
use Illuminate\Database\Eloquent\Relations\HasOne;
15+
16+
/**
17+
* @method int getSiteId()
18+
* @method Blog setSiteId(int $siteId)
19+
* @method string getDomain()
20+
* @method Blog setDomain(string $domain)
21+
* @method string getPath()
22+
* @method Blog setPath(string $path)
23+
* @method Carbon getRegistered()
24+
* @method Blog setRegistered($registered)
25+
* @method Carbon getLastUpdated()
26+
* @method Blog setLastUpdated($lastUpdated)
27+
* @method bool getPublic()
28+
* @method Blog setPublic(bool $public)
29+
* @method bool getArchived()
30+
* @method Blog setArchived(bool $archived)
31+
* @method bool getMature()
32+
* @method Blog setMature(bool $mature)
33+
* @method bool getSpam()
34+
* @method Blog setSpam(bool $spam)
35+
* @method bool getDeleted()
36+
* @method Blog setDeleted(bool $deleted)
37+
* @method int getLangId()
38+
* @method Blog setLangId(int $langId)
39+
*
40+
* @property-read Site $site
41+
* @property-read BlogVersion|null $version
42+
*/
43+
class Blog extends AbstractModel
44+
{
45+
public const CREATED_AT = self::REGISTERED;
46+
public const UPDATED_AT = self::LAST_UPDATED;
47+
48+
final public const BLOG_ID = 'blog_id';
49+
final public const SITE_ID = 'site_id';
50+
final public const DOMAIN = 'domain';
51+
final public const PATH = 'path';
52+
final public const REGISTERED = 'registered';
53+
final public const LAST_UPDATED = 'last_updated';
54+
final public const PUBLIC = 'public';
55+
final public const ARCHIVED = 'archived';
56+
final public const MATURE = 'mature';
57+
final public const SPAM = 'spam';
58+
final public const DELETED = 'deleted';
59+
final public const LANG_ID = 'lang_id';
60+
61+
protected $primaryKey = self::BLOG_ID;
62+
63+
protected bool $useBasePrefix = true;
64+
65+
protected $casts = [
66+
self::BLOG_ID => 'int',
67+
self::SITE_ID => 'int',
68+
self::REGISTERED => 'datetime',
69+
self::LAST_UPDATED => 'datetime',
70+
self::PUBLIC => 'bool',
71+
self::ARCHIVED => 'bool',
72+
self::MATURE => 'bool',
73+
self::SPAM => 'bool',
74+
self::DELETED => 'bool',
75+
self::LANG_ID => 'int',
76+
];
77+
78+
protected $table = 'blogs';
79+
80+
public function site(): BelongsTo
81+
{
82+
return $this->belongsTo(Site::class, self::SITE_ID);
83+
}
84+
85+
public function version(): HasOne
86+
{
87+
return $this->hasOne(BlogVersion::class, BlogVersion::BLOG_ID);
88+
}
89+
}

src/Models/Multisite/BlogVersion.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Dimitri BOUTEILLE (https://github.com/dimitriBouteille)
4+
* See LICENSE.txt for license details.
5+
*
6+
* Author: Dimitri BOUTEILLE <[email protected]>
7+
*/
8+
9+
namespace Dbout\WpOrm\Models\Multisite;
10+
11+
use Carbon\Carbon;
12+
use Dbout\WpOrm\Orm\AbstractModel;
13+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
14+
15+
/**
16+
* @method string getDbVersion()
17+
* @method BlogVersion setDbVersion(string $dbVersion)
18+
* @method Carbon getLastUpdated()
19+
* @method BlogVersion setLastUpdated($lastUpdated)
20+
*
21+
* @property-read Blog $blog
22+
*/
23+
class BlogVersion extends AbstractModel
24+
{
25+
public const CREATED_AT = null;
26+
public const UPDATED_AT = self::LAST_UPDATED;
27+
28+
final public const BLOG_ID = 'blog_id';
29+
final public const DB_VERSION = 'db_version';
30+
final public const LAST_UPDATED = 'last_updated';
31+
32+
protected bool $useBasePrefix = true;
33+
34+
protected $table = 'blog_versions';
35+
36+
protected $primaryKey = self::BLOG_ID;
37+
38+
protected $casts = [
39+
self::LAST_UPDATED => 'datetime',
40+
];
41+
42+
public function blog(): BelongsTo
43+
{
44+
return $this->belongsTo(Blog::class, self::BLOG_ID);
45+
}
46+
}
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Copyright © Dimitri BOUTEILLE (https://github.com/dimitriBouteille)
4+
* See LICENSE.txt for license details.
5+
*
6+
* Author: Dimitri BOUTEILLE <[email protected]>
7+
*/
8+
9+
namespace Dbout\WpOrm\Models\Multisite;
10+
11+
use Carbon\Carbon;
12+
use Dbout\WpOrm\Orm\AbstractModel;
13+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
14+
15+
/**
16+
* @method string getEmail()
17+
* @method RegistrationLog setEmail(string $email)
18+
* @method string getIP()
19+
* @method RegistrationLog setIP(string $ip)
20+
* @method int getBlogId()
21+
* @method RegistrationLog setBlogId(int $blogId)
22+
* @method Carbon getDateRegistered()
23+
* @method RegistrationLog setDateRegistered($dateRegistered)
24+
*
25+
* @property-read Blog|null $blog
26+
*/
27+
class RegistrationLog extends AbstractModel
28+
{
29+
public const CREATED_AT = self::DATE_REGISTERED;
30+
public const UPDATED_AT = null;
31+
32+
final public const ID = 'ID';
33+
final public const EMAIL = 'email';
34+
final public const IP = 'IP';
35+
final public const BLOG_ID = 'blog_id';
36+
final public const DATE_REGISTERED = 'date_registered';
37+
38+
protected bool $useBasePrefix = true;
39+
40+
protected $table = 'registration_log';
41+
42+
protected $primaryKey = self::ID;
43+
44+
protected $casts = [
45+
self::BLOG_ID => 'int',
46+
self::DATE_REGISTERED => 'datetime',
47+
];
48+
49+
public function blog(): BelongsTo
50+
{
51+
return $this->belongsTo(Blog::class, self::BLOG_ID);
52+
}
53+
54+
/**
55+
* @see getIP()
56+
*/
57+
public function getIpAttribute(): ?string
58+
{
59+
return $this->getAttributes()[self::IP] ?? null;
60+
}
61+
62+
/**
63+
* @see setIP()
64+
*/
65+
public function setIpAttribute(mixed $ip): self
66+
{
67+
$this->attributes[self::IP] = $ip;
68+
return $this;
69+
}
70+
}

src/Models/Multisite/Signup.php

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © Dimitri BOUTEILLE (https://github.com/dimitriBouteille)
4+
* See LICENSE.txt for license details.
5+
*
6+
* Author: Dimitri BOUTEILLE <[email protected]>
7+
*/
8+
9+
namespace Dbout\WpOrm\Models\Multisite;
10+
11+
use Carbon\Carbon;
12+
use Dbout\WpOrm\Models\User;
13+
use Dbout\WpOrm\Orm\AbstractModel;
14+
use Illuminate\Database\Eloquent\Relations\HasOne;
15+
16+
/**
17+
* @method string getDomain()
18+
* @method Signup setDomain(string $domain)
19+
* @method string getPath()
20+
* @method Signup setPath(string $path)
21+
* @method string getTitle()
22+
* @method Signup setTitle(string $title)
23+
* @method string getUserLogin()
24+
* @method Signup setUserLogin(string $userLogin)
25+
* @method string getUserEmail()
26+
* @method Signup setUserEmail(string $userEmail)
27+
* @method Carbon getRegistered()
28+
* @method Signup setRegistered($registered)
29+
* @method Carbon getActivated()
30+
* @method Signup setActivated($activated)
31+
* @method bool getActive()
32+
* @method Signup setActive(bool $active)
33+
* @method string getActivationKey()
34+
* @method Signup setActivationKey(string $activationKey)
35+
* @method string|null getMeta()
36+
* @method Signup setMeta(?string $meta)
37+
*
38+
* @property-read User|null $user
39+
*/
40+
class Signup extends AbstractModel
41+
{
42+
public const CREATED_AT = self::REGISTERED;
43+
public const UPDATED_AT = null;
44+
45+
final public const SIGNUP_ID = 'signup_id';
46+
final public const DOMAIN = 'domain';
47+
final public const PATH = 'path';
48+
final public const TITLE = 'title';
49+
final public const USER_LOGIN = 'user_login';
50+
final public const USER_EMAIL = 'user_email';
51+
final public const REGISTERED = 'registered';
52+
final public const ACTIVATED = 'activated';
53+
final public const ACTIVE = 'active';
54+
final public const ACTIVATION_KEY = 'activation_key';
55+
final public const META = 'meta';
56+
57+
protected bool $useBasePrefix = true;
58+
59+
protected $table = 'signups';
60+
61+
protected $primaryKey = self::SIGNUP_ID;
62+
63+
protected $casts = [
64+
self::REGISTERED => 'datetime',
65+
self::ACTIVATED => 'datetime',
66+
self::ACTIVE => 'bool',
67+
];
68+
69+
public function user(): HasOne
70+
{
71+
return $this->hasOne(User::class, User::EMAIL, self::USER_EMAIL);
72+
}
73+
}

src/Models/Multisite/Site.php

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Dimitri BOUTEILLE (https://github.com/dimitriBouteille)
4+
* See LICENSE.txt for license details.
5+
*
6+
* Author: Dimitri BOUTEILLE <[email protected]>
7+
*/
8+
9+
namespace Dbout\WpOrm\Models\Multisite;
10+
11+
use Dbout\WpOrm\Concerns\HasMetas;
12+
use Dbout\WpOrm\MetaMappingConfig;
13+
use Dbout\WpOrm\Orm\AbstractModel;
14+
use Illuminate\Database\Eloquent\Collection;
15+
use Illuminate\Database\Eloquent\Relations\HasMany;
16+
17+
/**
18+
* @method string getDomain()
19+
* @method Site setDomain(string $domain)
20+
* @method string getPath()
21+
* @method Site setPath(string $path)
22+
*
23+
* @property-read Collection<SiteMeta> $metas
24+
* @property-read Collection<Blog> $blogs
25+
*/
26+
class Site extends AbstractModel
27+
{
28+
use HasMetas;
29+
30+
public const CREATED_AT = null;
31+
public const UPDATED_AT = null;
32+
33+
final public const ID = 'id';
34+
final public const DOMAIN = 'domain';
35+
final public const PATH = 'path';
36+
37+
protected bool $useBasePrefix = true;
38+
39+
protected $table = 'site';
40+
41+
protected $primaryKey = self::ID;
42+
43+
public function blogs(): HasMany
44+
{
45+
return $this->hasMany(Blog::class, Blog::SITE_ID);
46+
}
47+
48+
public function getMetaConfigMapping(): MetaMappingConfig
49+
{
50+
return new MetaMappingConfig(SiteMeta::class, SiteMeta::SITE_ID);
51+
}
52+
}

0 commit comments

Comments
 (0)