Skip to content

Commit 1e85d97

Browse files
committed
stop using SerializeModels
1 parent df8cd66 commit 1e85d97

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

src/Ushahidi/Core/Concerns/SiteAware.php

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,62 @@
55
use Ushahidi\Core\Facade\Site;
66
use Illuminate\Support\Facades\Log;
77
use Illuminate\Support\Facades\Event;
8-
use Illuminate\Queue\SerializesModels;
8+
use Illuminate\Queue\SerializesAndRestoresModelIdentifiers;
9+
use ReflectionClass;
10+
use ReflectionProperty;
911

1012
trait SiteAware
1113
{
1214
/**
1315
* @var int The hostname ID of the previously active deployment
1416
*/
1517
protected $site;
18+
use SerializesAndRestoresModelIdentifiers;
1619

17-
use SerializesModels {
18-
__sleep as serializedSleep;
19-
__wakeup as serializedWakeup;
20-
}
2120

2221
public function __sleep()
2322
{
24-
if (!$this->site) {
25-
$this->site = Site::instance()->getId();
26-
Log::debug('Saving deployment id for job', [$this->site]);
27-
}
23+
$this->site = Site::instance()->getId();
24+
25+
$properties = (new ReflectionClass($this))->getProperties();
2826

29-
$attributes = $this->serializedSleep();
27+
foreach ($properties as $property) {
28+
$property->setValue($this, $this->getSerializedPropertyValue(
29+
$this->getPropertyValue($property)
30+
));
31+
}
3032

31-
return $attributes;
33+
return array_values(array_filter(array_map(function ($p) {
34+
return $p->isStatic() ? null : $p->getName();
35+
}, $properties)));
3236
}
3337

3438
public function __wakeup()
3539
{
3640
if (isset($this->site) && $this->site) {
37-
Log::debug('Restoring deployment id for job', [$this->site]);
3841
Event::dispatch('site.restored', ['site' => $this->site]);
3942
}
43+
foreach ((new ReflectionClass($this))->getProperties() as $property) {
44+
if ($property->isStatic()) {
45+
continue;
46+
}
47+
48+
$property->setValue($this, $this->getRestoredPropertyValue(
49+
$this->getPropertyValue($property)
50+
));
51+
}
52+
}
53+
54+
/**
55+
* Get the property value for the given property.
56+
*
57+
* @param \ReflectionProperty $property
58+
* @return mixed
59+
*/
60+
protected function getPropertyValue(ReflectionProperty $property)
61+
{
62+
$property->setAccessible(true);
4063

41-
$this->serializedWakeup();
64+
return $property->getValue($this);
4265
}
4366
}

0 commit comments

Comments
 (0)