Skip to content

Commit 95fa5d5

Browse files
committed
Issue #425: Revert changes that interfered with the Browscap mapping
Signed-off-by: bota <Bota@dotkernel.com>
1 parent 04ac07d commit 95fa5d5

4 files changed

Lines changed: 43 additions & 149 deletions

File tree

src/Admin/src/Service/AdminLoginService.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ public function getAdminLogins(array $params): array
5757
'login.osVersion',
5858
'login.clientType',
5959
'login.clientName',
60-
'login.deviceBrand',
61-
'login.deviceModel',
62-
'login.osPlatform',
63-
'login.clientEngine',
64-
'login.clientVersion',
60+
'login.isCrawler',
6561
'login.loginStatus',
6662
'login.identity',
6763
'login.created',
@@ -115,8 +111,7 @@ private function logAdminVisit(array $serverParams, string $name, SuccessFailure
115111
*/
116112
$browser = new stdClass();
117113
if (ini_get('browscap')) {
118-
$result = get_browser($_SERVER['HTTP_USER_AGENT']);
119-
$browser = $result instanceof stdClass ? $result : $browser;
114+
$browser = get_browser($_SERVER['HTTP_USER_AGENT']);
120115
}
121116

122117
$adminLogin = (new AdminLogin())
@@ -133,11 +128,7 @@ private function logAdminVisit(array $serverParams, string $name, SuccessFailure
133128
->setClientType(! empty($browser->browser_type) ? $browser->browser_type : null)
134129
->setClientName(! empty($browser->browser) ? $browser->browser : null)
135130
->setLoginStatus($status)
136-
->setDeviceBrand(! empty($browser->device_brand) ? $browser->device_brand : null)
137-
->setDeviceBrand(! empty($browser->device_model) ? $browser->device_model : null)
138-
->setDeviceBrand(! empty($browser->platform_version) ? $browser->platform_version : null)
139-
->setDeviceBrand(! empty($browser->browser_engine) ? $browser->browser_engine : null)
140-
->setDeviceBrand(! empty($browser->browser_version) ? $browser->browser_version : null)
131+
->setIsCrawler(! empty($browser->crawler) ? YesNoEnum::Yes : YesNoEnum::No)
141132
->setIdentity($name);
142133

143134
$this->adminLoginRepository->saveResource($adminLogin);

src/Admin/templates/admin/list-admin-login.html.twig

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,8 @@
9191
<th class="column-login-clientName">
9292
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.clientName', 'Client Name') }}
9393
</th>
94-
<th class="column-login-deviceBrand">
95-
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.deviceBrand', 'Device Brand') }}
96-
</th>
97-
<th class="column-login-deviceModel">
98-
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.deviceModel', 'Device Model') }}
99-
</th>
100-
<th class="column-login-osPlatform">
101-
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.osPlatform', 'Os Platform') }}
102-
</th>
103-
<th class="column-login-clientEngine">
104-
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.clientEngine', 'Client Engine') }}
105-
</th>
106-
<th class="column-login-clientVersion">
107-
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.clientVersion', 'Client Version') }}
94+
<th class="column-login-isCrawler">
95+
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.isCrawler', 'Is Crawler') }}
10896
</th>
10997
<th class="column-login-created">
11098
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.created', 'Created') }}
@@ -138,11 +126,13 @@
138126
<td class="column-login-osVersion">{{ login.osVersion }}</td>
139127
<td class="column-login-clientType">{{ login.clientType }}</td>
140128
<td class="column-login-clientName">{{ login.clientName }}</td>
141-
<td class="column-login-deviceBrand">{{ login.deviceBrand }}</td>
142-
<td class="column-login-deviceModel">{{ login.deviceModel }}</td>
143-
<td class="column-login-osPlatform">{{ login.osPlatform }}</td>
144-
<td class="column-login-clientEngine">{{ login.clientEngine }}</td>
145-
<td class="column-login-clientVersion">{{ login.clientVersion }}</td>
129+
<td class="column-login-isCrawler">
130+
{% if login.isCrawler.value == 'yes' %}
131+
<span class="badge text-bg-primary">Yes</span>
132+
{% else %}
133+
<span class="badge text-bg-secondary">No</span>
134+
{% endif %}
135+
</td>
146136
<td class="column-login-created">{{ login.getCreated()|date('Y-m-d H:i:s') }}</td>
147137
</tr>
148138
{% endfor %}

src/Core/src/Admin/src/Entity/AdminLogin.php

Lines changed: 27 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ class AdminLogin extends AbstractEntity
3939
#[ORM\Column(name: 'deviceType', type: 'string', length: 191, nullable: true)]
4040
protected ?string $deviceType = null;
4141

42-
#[ORM\Column(name: 'deviceBrand', type: 'string', length: 191, nullable: true)]
43-
protected ?string $deviceBrand = null;
44-
45-
#[ORM\Column(name: 'deviceModel', type: 'string', length: 40, nullable: true)]
46-
protected ?string $deviceModel = null;
47-
4842
#[ORM\Column(type: 'yes_no_enum', nullable: true, enumType: YesNoEnum::class)]
4943
protected YesNoEnum $isMobile = YesNoEnum::No;
5044

@@ -54,20 +48,14 @@ class AdminLogin extends AbstractEntity
5448
#[ORM\Column(name: 'osVersion', type: 'string', length: 191, nullable: true)]
5549
protected ?string $osVersion = null;
5650

57-
#[ORM\Column(name: 'osPlatform', type: 'string', length: 191, nullable: true)]
58-
protected ?string $osPlatform = null;
59-
6051
#[ORM\Column(name: 'clientType', type: 'string', length: 191, nullable: true)]
6152
protected ?string $clientType = null;
6253

6354
#[ORM\Column(name: 'clientName', type: 'string', length: 191, nullable: true)]
6455
protected ?string $clientName = null;
6556

66-
#[ORM\Column(name: 'clientEngine', type: 'string', length: 191, nullable: true)]
67-
protected ?string $clientEngine = null;
68-
69-
#[ORM\Column(name: 'clientVersion', type: 'string', length: 191, nullable: true)]
70-
protected ?string $clientVersion = null;
57+
#[ORM\Column(type: 'yes_no_enum', nullable: true, enumType: YesNoEnum::class)]
58+
protected YesNoEnum $isCrawler = YesNoEnum::No;
7159

7260
#[ORM\Column(type: 'success_failure_enum', nullable: true, enumType: SuccessFailureEnum::class)]
7361
protected SuccessFailureEnum $loginStatus = SuccessFailureEnum::Fail;
@@ -144,30 +132,6 @@ public function setDeviceType(?string $deviceType): self
144132
return $this;
145133
}
146134

147-
public function getDeviceBrand(): ?string
148-
{
149-
return $this->deviceBrand;
150-
}
151-
152-
public function setDeviceBrand(?string $deviceBrand): self
153-
{
154-
$this->deviceBrand = $deviceBrand;
155-
156-
return $this;
157-
}
158-
159-
public function getDeviceModel(): ?string
160-
{
161-
return $this->deviceModel;
162-
}
163-
164-
public function setDeviceModel(?string $deviceModel): self
165-
{
166-
$this->deviceModel = $deviceModel;
167-
168-
return $this;
169-
}
170-
171135
public function getIsMobile(): ?YesNoEnum
172136
{
173137
return $this->isMobile;
@@ -204,18 +168,6 @@ public function setOsVersion(?string $osVersion): self
204168
return $this;
205169
}
206170

207-
public function getOsPlatform(): ?string
208-
{
209-
return $this->osPlatform;
210-
}
211-
212-
public function setOsPlatform(?string $osPlatform): self
213-
{
214-
$this->osPlatform = $osPlatform;
215-
216-
return $this;
217-
}
218-
219171
public function getClientType(): ?string
220172
{
221173
return $this->clientType;
@@ -240,38 +192,26 @@ public function setClientName(?string $clientName): self
240192
return $this;
241193
}
242194

243-
public function getClientEngine(): ?string
244-
{
245-
return $this->clientEngine;
246-
}
247-
248-
public function setClientEngine(?string $clientEngine): self
249-
{
250-
$this->clientEngine = $clientEngine;
251-
252-
return $this;
253-
}
254-
255-
public function getClientVersion(): ?string
195+
public function getLoginStatus(): ?SuccessFailureEnum
256196
{
257-
return $this->clientVersion;
197+
return $this->loginStatus;
258198
}
259199

260-
public function setClientVersion(?string $clientVersion): self
200+
public function setLoginStatus(SuccessFailureEnum $loginStatus): self
261201
{
262-
$this->clientVersion = $clientVersion;
202+
$this->loginStatus = $loginStatus;
263203

264204
return $this;
265205
}
266206

267-
public function getLoginStatus(): ?SuccessFailureEnum
207+
public function getIsCrawler(): ?YesNoEnum
268208
{
269-
return $this->loginStatus;
209+
return $this->isCrawler;
270210
}
271211

272-
public function setLoginStatus(SuccessFailureEnum $loginStatus): self
212+
public function setIsCrawler(YesNoEnum $isCrawler): self
273213
{
274-
$this->loginStatus = $loginStatus;
214+
$this->isCrawler = $isCrawler;
275215

276216
return $this;
277217
}
@@ -285,16 +225,12 @@ public function setLoginStatus(SuccessFailureEnum $loginStatus): self
285225
* continent: string|null,
286226
* organization: string|null,
287227
* deviceType: string|null,
288-
* deviceBrand: string|null,
289-
* deviceModel: string|null,
290228
* isMobile: string,
291229
* osName: string|null,
292230
* osVersion: string|null,
293-
* osPlatform: string|null,
294231
* clientType: string|null,
295232
* clientName: string|null,
296-
* clientEngine: string|null,
297-
* clientVersion: string|null,
233+
* isCrawler: 'no'|'yes',
298234
* loginStatus: string,
299235
* created: DateTimeImmutable|null,
300236
* updated: DateTimeImmutable|null,
@@ -303,26 +239,22 @@ public function setLoginStatus(SuccessFailureEnum $loginStatus): self
303239
public function getArrayCopy(): array
304240
{
305241
return [
306-
'id' => $this->id->toString(),
307-
'identity' => $this->identity,
308-
'adminIp' => $this->adminIp,
309-
'country' => $this->country,
310-
'continent' => $this->continent,
311-
'organization' => $this->organization,
312-
'deviceType' => $this->deviceType,
313-
'deviceBrand' => $this->deviceBrand,
314-
'deviceModel' => $this->deviceModel,
315-
'isMobile' => $this->isMobile->value,
316-
'osName' => $this->osName,
317-
'osVersion' => $this->osVersion,
318-
'osPlatform' => $this->osPlatform,
319-
'clientType' => $this->clientType,
320-
'clientName' => $this->clientName,
321-
'clientEngine' => $this->clientEngine,
322-
'clientVersion' => $this->clientVersion,
323-
'loginStatus' => $this->loginStatus->value,
324-
'created' => $this->created,
325-
'updated' => $this->updated,
242+
'id' => $this->id->toString(),
243+
'identity' => $this->identity,
244+
'adminIp' => $this->adminIp,
245+
'country' => $this->country,
246+
'continent' => $this->continent,
247+
'organization' => $this->organization,
248+
'deviceType' => $this->deviceType,
249+
'isMobile' => $this->isMobile->value,
250+
'osName' => $this->osName,
251+
'osVersion' => $this->osVersion,
252+
'clientType' => $this->clientType,
253+
'clientName' => $this->clientName,
254+
'isCrawler' => $this->isCrawler->value,
255+
'loginStatus' => $this->loginStatus->value,
256+
'created' => $this->created,
257+
'updated' => $this->updated,
326258
];
327259
}
328260
}

test/Unit/Admin/Entity/AdminLoginTest.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,11 @@ public function testAccessors(): void
9393
$this->assertSame(AdminLogin::class, $adminLogin::class);
9494
$this->assertSame('test', $adminLogin->getClientName());
9595

96-
$this->assertNull($adminLogin->getDeviceBrand());
97-
$adminLogin = $adminLogin->setDeviceBrand('test');
96+
$this->assertSame(YesNoEnum::No, $adminLogin->getIsCrawler());
97+
$adminLogin = $adminLogin->setIsCrawler(YesNoEnum::Yes);
9898
$this->assertSame(AdminLogin::class, $adminLogin::class);
99-
$this->assertSame('test', $adminLogin->getDeviceBrand());
100-
101-
$this->assertNull($adminLogin->getDeviceModel());
102-
$adminLogin = $adminLogin->setDeviceModel('test');
103-
$this->assertSame(AdminLogin::class, $adminLogin::class);
104-
$this->assertSame('test', $adminLogin->getDeviceModel());
105-
106-
$this->assertNull($adminLogin->getOsPlatform());
107-
$adminLogin = $adminLogin->setOsPlatform('test');
108-
$this->assertSame(AdminLogin::class, $adminLogin::class);
109-
$this->assertSame('test', $adminLogin->getOsPlatform());
110-
111-
$this->assertNull($adminLogin->getClientEngine());
112-
$adminLogin = $adminLogin->setClientEngine('test');
113-
$this->assertSame(AdminLogin::class, $adminLogin::class);
114-
$this->assertSame('test', $adminLogin->getClientEngine());
115-
116-
$this->assertNull($adminLogin->getClientVersion());
117-
$adminLogin = $adminLogin->setClientVersion('test');
118-
$this->assertSame(AdminLogin::class, $adminLogin::class);
119-
$this->assertSame('test', $adminLogin->getClientVersion());
99+
$this->assertNotNull($adminLogin->getIsCrawler());
100+
$this->assertSame('yes', $adminLogin->getIsCrawler()->value);
120101

121102
$this->assertSame(SuccessFailureEnum::Fail, $adminLogin->getLoginStatus());
122103
$adminLogin = $adminLogin->setLoginStatus(SuccessFailureEnum::Success);

0 commit comments

Comments
 (0)