Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Письменов Дмитрий Иванович
/
yourroomads
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6f86a701
authored
Jun 08, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19465 Реализация синхронизации данных по РК.
1 parent
879faa7e
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
285 additions
and
85 deletions
app/Console/Commands/AdGroupsUpdate.php
app/Console/Commands/CampaignsCheckChange.php
app/Console/Commands/CampaignsLoadUpdated.php
app/Console/Commands/CampaignsUpdate.php
app/Models/AdGroup.php
app/Models/Campaigns.php
app/Models/Contact.php
app/Models/Dictionary.php
app/Models/Limits.php
app/Models/Organization.php
app/Models/Pivots/DictionaryCampaign.php
app/Models/Pivots/GoalAdGroup.php
app/Models/Tokens.php
app/Models/User.php
app/Models/Variable.php
app/Service/Requests/Direct/CheckCampaignsChanges.php
app/Service/Requests/Direct/CheckChanges.php
resources/js/Pages/Tokens/Edit.vue
tests/Unit/CheckCampaignsTest.php
tests/Unit/LimitsTest.php
app/Console/Commands/AdGroupsUpdate.php
View file @
6f86a70
...
@@ -42,10 +42,10 @@ class AdGroupsUpdate extends Command
...
@@ -42,10 +42,10 @@ class AdGroupsUpdate extends Command
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternal
Synchroniz
ed.groupsForExternalForNeedUpdated'
)
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternal
Updat
ed.groupsForExternalForNeedUpdated'
)
->
with
([
->
with
([
'dictionaryCampaignsEnabledForExternal
Synchroniz
ed.groupsForExternalForNeedUpdated.dictionaryCampaign'
,
'dictionaryCampaignsEnabledForExternal
Updat
ed.groupsForExternalForNeedUpdated.dictionaryCampaign'
,
'dictionaryCampaignsEnabledForExternal
Synchroniz
ed.groupsForExternalForNeedUpdated.group'
,
'dictionaryCampaignsEnabledForExternal
Updat
ed.groupsForExternalForNeedUpdated.group'
,
])
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
->
get
();
...
@@ -57,7 +57,7 @@ class AdGroupsUpdate extends Command
...
@@ -57,7 +57,7 @@ class AdGroupsUpdate extends Command
$factory
->
getRequest
(
'AdGroup'
,
'update'
)
$factory
->
getRequest
(
'AdGroup'
,
'update'
)
->
call
([
->
call
([
'goalAdGroups'
=>
$token
->
dictionaryCampaignsEnabledForExternal
->
pluck
(
'dictionaryCampaignsEnabledForExternalSynchroniz
ed'
)
'goalAdGroups'
=>
$token
->
dictionaryCampaignsEnabledForExternal
Updated
->
pluck
(
'groupsForExternalForNeedUpdat
ed'
)
->
collapse
(),
->
collapse
(),
]);
]);
}
}
...
...
app/Console/Commands/CampaignsCheckChange.php
View file @
6f86a70
...
@@ -50,7 +50,8 @@ class CampaignsCheckChange extends Command
...
@@ -50,7 +50,8 @@ class CampaignsCheckChange extends Command
->
call
();
->
call
();
}
}
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternal'
)
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalUpdated'
)
->
with
(
'dictionaryCampaignsEnabledForExternalUpdated'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
foreach
(
$tokens
as
$token
)
{
...
...
app/Console/Commands/CampaignsLoadUpdated.php
View file @
6f86a70
...
@@ -47,7 +47,7 @@ class CampaignsLoadUpdated extends Command
...
@@ -47,7 +47,7 @@ class CampaignsLoadUpdated extends Command
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$campaigns
=
Campaigns
::
forUpdatedSelf
()
->
get
();
$campaigns
=
Campaigns
::
for
Enabled
()
->
for
UpdatedSelf
()
->
get
();
if
(
!
$campaigns
->
count
())
{
if
(
!
$campaigns
->
count
())
{
return
;
return
;
}
}
...
...
app/Console/Commands/CampaignsUpdate.php
View file @
6f86a70
...
@@ -42,8 +42,8 @@ class CampaignsUpdate extends Command
...
@@ -42,8 +42,8 @@ class CampaignsUpdate extends Command
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternal
Synchroniz
edNeedUpdated'
)
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternal
Updat
edNeedUpdated'
)
->
with
(
'dictionaryCampaignsEnabledForExternal
Synchroniz
edNeedUpdated.campaign'
)
->
with
(
'dictionaryCampaignsEnabledForExternal
Updat
edNeedUpdated.campaign'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
->
get
();
...
@@ -53,7 +53,7 @@ class CampaignsUpdate extends Command
...
@@ -53,7 +53,7 @@ class CampaignsUpdate extends Command
$factory
->
getRequest
(
'Campaigns'
,
'update'
)
$factory
->
getRequest
(
'Campaigns'
,
'update'
)
->
call
([
->
call
([
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsEnabledForExternal
Synchroniz
edNeedUpdated
,
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsEnabledForExternal
Updat
edNeedUpdated
,
]);
]);
}
}
...
...
app/Models/AdGroup.php
View file @
6f86a70
...
@@ -173,9 +173,13 @@ class AdGroup extends Model
...
@@ -173,9 +173,13 @@ class AdGroup extends Model
});
});
}
}
public
function
scopeForUpdatedSelf
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedSelf
(
$query
)
{
{
$query
->
whereNotNull
(
"
{
$query
->
getModel
()
->
getTable
()
}
.updated_self"
);
return
$query
->
whereNotNull
(
"
{
$query
->
getModel
()
->
getTable
()
}
.updated_self"
);
}
}
public
function
goalGroups
()
public
function
goalGroups
()
...
...
app/Models/Campaigns.php
View file @
6f86a70
...
@@ -193,7 +193,7 @@ class Campaigns extends Model
...
@@ -193,7 +193,7 @@ class Campaigns extends Model
if
(
DictionaryCampaign
::
getPropertiesCopyWithPivot
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
if
(
DictionaryCampaign
::
getPropertiesCopyWithPivot
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
return
$campaign
->
{
$property_name
}
!==
$campaign
->
getOriginal
(
$property_name
);
return
$campaign
->
{
$property_name
}
!==
$campaign
->
getOriginal
(
$property_name
);
}))
{
}))
{
$campaign
->
dictionaryCampaigns
()
->
enabled
()
->
u
pdated
()
->
update
(
$campaign
->
dictionaryCampaigns
()
->
enabled
()
->
forU
pdated
()
->
update
(
DictionaryCampaign
::
copyPropertyFromMain
(
$campaign
)
DictionaryCampaign
::
copyPropertyFromMain
(
$campaign
)
);
);
}
}
...
@@ -339,37 +339,67 @@ class Campaigns extends Model
...
@@ -339,37 +339,67 @@ class Campaigns extends Model
->
withTimestamps
();
->
withTimestamps
();
}
}
public
function
scopeForUpdatedSelf
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedSelf
(
$query
)
{
{
$query
->
whereNotNull
(
'updated_self'
);
return
$query
->
whereNotNull
(
'updated_self'
);
}
}
public
function
scopeForUpdatedChildren
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedChildren
(
$query
)
{
{
$query
->
whereNotNull
(
'updated_children'
);
return
$query
->
whereNotNull
(
'updated_children'
);
}
}
public
function
scopeForGroupsLoadable
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForGroupsLoadable
(
$query
)
{
{
$query
->
whereNull
(
'groups_loaded_at'
);
return
$query
->
whereNull
(
'groups_loaded_at'
);
}
}
public
function
scopeForManaged
(
Builder
$query
,
$manage
=
true
)
/**
* @param Builder $query
* @param bool $manage
* @return Builder
*/
public
function
scopeForManaged
(
$query
,
$manage
=
true
)
{
{
$query
->
where
(
'manage'
,
$manage
);
return
$query
->
where
(
'manage'
,
$manage
);
}
}
public
function
scopeForEnabled
(
Builder
$query
,
$enabled
=
true
)
/**
* @param Builder $query
* @param bool $enabled
* @return Builder
*/
public
function
scopeForEnabled
(
$query
,
$enabled
=
true
)
{
{
$query
->
where
(
'enabled'
,
$enabled
);
return
$query
->
where
(
'enabled'
,
$enabled
);
}
}
public
function
scopeDisabled
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeDisabled
(
$query
)
{
{
return
$query
->
whereNotNull
(
'disabled_at'
);
return
$query
->
whereNotNull
(
'disabled_at'
);
}
}
public
function
scopeNotDisabled
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeNotDisabled
(
$query
)
{
{
return
$query
->
whereNull
(
'disabled_at'
);
return
$query
->
whereNull
(
'disabled_at'
);
}
}
...
...
app/Models/Contact.php
View file @
6f86a70
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
App\Models
;
namespace
App\Models
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
/**
/**
...
@@ -53,24 +54,23 @@ class Contact extends Model
...
@@ -53,24 +54,23 @@ class Contact extends Model
{
{
use
SoftDeletes
;
use
SoftDeletes
;
public
function
organization
()
/**
{
* @param Builder $query
return
$this
->
belongsTo
(
Organization
::
class
);
* @return Builder
}
*/
public
function
getNameAttribute
()
{
return
$this
->
first_name
.
' '
.
$this
->
last_name
;
}
public
function
scopeOrderByName
(
$query
)
public
function
scopeOrderByName
(
$query
)
{
{
$query
->
orderBy
(
'last_name'
)
->
orderBy
(
'first_name'
);
return
$query
->
orderBy
(
'last_name'
)
->
orderBy
(
'first_name'
);
}
}
/**
* @param Builder $query
* @param array $filters
* @return Builder
*/
public
function
scopeFilter
(
$query
,
array
$filters
)
public
function
scopeFilter
(
$query
,
array
$filters
)
{
{
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
return
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
$query
->
where
(
function
(
$query
)
use
(
$search
)
{
$query
->
where
(
function
(
$query
)
use
(
$search
)
{
$query
->
where
(
'first_name'
,
'like'
,
'%'
.
$search
.
'%'
)
$query
->
where
(
'first_name'
,
'like'
,
'%'
.
$search
.
'%'
)
->
orWhere
(
'last_name'
,
'like'
,
'%'
.
$search
.
'%'
)
->
orWhere
(
'last_name'
,
'like'
,
'%'
.
$search
.
'%'
)
...
@@ -87,4 +87,14 @@ class Contact extends Model
...
@@ -87,4 +87,14 @@ class Contact extends Model
}
}
});
});
}
}
public
function
organization
()
{
return
$this
->
belongsTo
(
Organization
::
class
);
}
public
function
getNameAttribute
()
{
return
$this
->
first_name
.
' '
.
$this
->
last_name
;
}
}
}
app/Models/Dictionary.php
View file @
6f86a70
...
@@ -40,7 +40,11 @@ class Dictionary extends Model
...
@@ -40,7 +40,11 @@ class Dictionary extends Model
{
{
CONST
CITY
=
'City'
;
CONST
CITY
=
'City'
;
public
function
scopeDefaultOrderBy
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeDefaultOrderBy
(
$query
)
{
{
return
$query
->
orderBy
(
'name'
);
return
$query
->
orderBy
(
'name'
);
}
}
...
...
app/Models/Limits.php
View file @
6f86a70
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
App\Models
;
namespace
App\Models
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
...
@@ -38,8 +39,12 @@ class Limits extends Model
...
@@ -38,8 +39,12 @@ class Limits extends Model
{
{
use
HasFactory
;
use
HasFactory
;
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeComplited
(
$query
)
public
function
scopeComplited
(
$query
)
{
{
$query
->
where
(
'reserved'
,
0
);
return
$query
->
where
(
'reserved'
,
0
);
}
}
}
}
app/Models/Organization.php
View file @
6f86a70
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
App\Models
;
namespace
App\Models
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
/**
/**
...
@@ -53,9 +54,14 @@ class Organization extends Model
...
@@ -53,9 +54,14 @@ class Organization extends Model
return
$this
->
hasMany
(
Contact
::
class
);
return
$this
->
hasMany
(
Contact
::
class
);
}
}
/**
* @param Builder $query
* @param array $filters
* @return Builder
*/
public
function
scopeFilter
(
$query
,
array
$filters
)
public
function
scopeFilter
(
$query
,
array
$filters
)
{
{
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
return
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
$query
->
where
(
'name'
,
'like'
,
'%'
.
$search
.
'%'
);
$query
->
where
(
'name'
,
'like'
,
'%'
.
$search
.
'%'
);
})
->
when
(
$filters
[
'trashed'
]
??
null
,
function
(
$query
,
$trashed
)
{
})
->
when
(
$filters
[
'trashed'
]
??
null
,
function
(
$query
,
$trashed
)
{
if
(
$trashed
===
'with'
)
{
if
(
$trashed
===
'with'
)
{
...
...
app/Models/Pivots/DictionaryCampaign.php
View file @
6f86a70
...
@@ -44,7 +44,7 @@ use Illuminate\Support\Collection;
...
@@ -44,7 +44,7 @@ use Illuminate\Support\Collection;
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forNotExternal()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forNotExternal()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign needUpdated()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign needUpdated()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign enabled($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign enabled($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
u
pdated($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign
forU
pdated($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synced($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synced($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synchronized()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synchronized()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forUpdatedSelf()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forUpdatedSelf()
...
@@ -174,62 +174,113 @@ class DictionaryCampaign extends Pivot
...
@@ -174,62 +174,113 @@ class DictionaryCampaign extends Pivot
})
->
all
();
})
->
all
();
}
}
public
function
scopeDisabled
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeDisabled
(
$query
)
{
{
return
$query
->
whereNotNull
(
'disabled_at'
);
return
$query
->
whereNotNull
(
'disabled_at'
);
}
}
public
function
scopeNotDisabled
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeNotDisabled
(
$query
)
{
{
return
$query
->
whereNull
(
'disabled_at'
);
return
$query
->
whereNull
(
'disabled_at'
);
}
}
public
function
scopeForExternal
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForExternal
(
$query
)
{
{
return
$query
->
whereNotNull
(
'external_id'
);
return
$query
->
whereNotNull
(
'external_id'
);
}
}
public
function
scopeForNotExternal
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForNotExternal
(
$query
)
{
{
return
$query
->
whereNull
(
'external_id'
);
return
$query
->
whereNull
(
'external_id'
);
}
}
public
function
scopeEnabled
(
Builder
$query
,
$enabled
=
true
)
/**
* @param Builder $query
* @param bool $enabled
* @return Builder
*/
public
function
scopeEnabled
(
$query
,
$enabled
=
true
)
{
{
return
$query
->
where
(
'enabled'
,
$enabled
);
return
$query
->
where
(
'enabled'
,
$enabled
);
}
}
public
function
scopeUpdated
(
Builder
$query
,
$updated
=
true
)
/**
* @param Builder $query
* @param bool $updated
* @return Builder
*/
public
function
scopeForUpdated
(
$query
,
$updated
=
true
)
{
{
return
$query
->
where
(
'updated'
,
$updated
);
return
$query
->
where
(
'updated'
,
$updated
);
}
}
public
function
scopeNeedUpdated
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeNeedUpdated
(
$query
)
{
{
return
$query
->
whereNotNull
(
'updated_need'
);
return
$query
->
whereNotNull
(
'updated_need'
);
}
}
public
function
scopeSynced
(
Builder
$query
,
$synced
=
true
)
/**
* @param Builder $query
* @param bool $synced
* @return Builder
*/
public
function
scopeSynced
(
$query
,
$synced
=
true
)
{
{
return
$query
->
where
(
'synced'
,
$synced
);
return
$query
->
where
(
'synced'
,
$synced
);
}
}
public
function
scopeSynchronized
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeSynchronized
(
$query
)
{
{
return
$query
->
synced
()
->
u
pdated
();
return
$query
->
synced
()
->
forU
pdated
();
}
}
public
function
scopeForUpdatedSelf
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedSelf
(
$query
)
{
{
$query
->
whereNotNull
(
'updated_self'
);
return
$query
->
whereNotNull
(
'updated_self'
);
}
}
public
function
scopeForUpdatedChildren
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedChildren
(
$query
)
{
{
$query
->
whereNotNull
(
'updated_children'
);
return
$query
->
whereNotNull
(
'updated_children'
);
}
}
public
function
scopeJoinDictionaries
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeJoinDictionaries
(
$query
)
{
{
$dictionary_model
=
Dictionary
::
getModel
();
$dictionary_model
=
Dictionary
::
getModel
();
...
...
app/Models/Pivots/GoalAdGroup.php
View file @
6f86a70
...
@@ -134,24 +134,40 @@ class GoalAdGroup extends Pivot
...
@@ -134,24 +134,40 @@ class GoalAdGroup extends Pivot
->
all
();
->
all
();
}
}
public
function
scopeForExternal
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForExternal
(
$query
)
{
{
return
$query
->
whereNotNull
(
'external_id'
);
return
$query
->
whereNotNull
(
'external_id'
);
}
}
public
function
scopeForNotExternal
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForNotExternal
(
$query
)
{
{
return
$query
->
whereNull
(
'external_id'
);
return
$query
->
whereNull
(
'external_id'
);
}
}
public
function
scopeNeedUpdated
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeNeedUpdated
(
$query
)
{
{
return
$query
->
whereNotNull
(
'updated_need'
);
return
$query
->
whereNotNull
(
'updated_need'
);
}
}
public
function
scopeForUpdatedSelf
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForUpdatedSelf
(
$query
)
{
{
$query
->
whereNotNull
(
'updated_self'
);
return
$query
->
whereNotNull
(
'updated_self'
);
}
}
public
function
group
()
public
function
group
()
...
...
app/Models/Tokens.php
View file @
6f86a70
...
@@ -4,6 +4,7 @@ namespace App\Models;
...
@@ -4,6 +4,7 @@ namespace App\Models;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\DictionaryCampaign
;
use
Carbon\Carbon
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
/**
/**
...
@@ -39,9 +40,11 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -39,9 +40,11 @@ use Illuminate\Database\Eloquent\Model;
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForNotExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForNotExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsNotEnabledForExternalNotDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsNotEnabledForExternalNotDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalUpdated
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronized
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronized
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternal
Synchroniz
edNeedUpdated
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternal
Updat
edNeedUpdated
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $campaignsForManaged
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $campaignsForManaged
...
@@ -112,9 +115,14 @@ class Tokens extends Model
...
@@ -112,9 +115,14 @@ class Tokens extends Model
:
Carbon
::
now
()
->
addDays
(
-
1
);
:
Carbon
::
now
()
->
addDays
(
-
1
);
}
}
/**
* @param Builder $query
* @param array $filters
* @return Builder
*/
public
function
scopeFilter
(
$query
,
array
$filters
)
public
function
scopeFilter
(
$query
,
array
$filters
)
{
{
$query
->
when
(
$filters
[
'login'
]
??
null
,
function
(
$query
,
$search
)
{
return
$query
->
when
(
$filters
[
'login'
]
??
null
,
function
(
$query
,
$search
)
{
$query
->
where
(
'login'
,
'like'
,
'%'
.
$search
.
'%'
);
$query
->
where
(
'login'
,
'like'
,
'%'
.
$search
.
'%'
);
})
->
when
(
$filters
[
'type'
]
??
null
,
function
(
$query
,
$type
)
{
})
->
when
(
$filters
[
'type'
]
??
null
,
function
(
$query
,
$type
)
{
$query
->
where
(
'type'
,
$type
);
$query
->
where
(
'type'
,
$type
);
...
@@ -185,7 +193,17 @@ class Tokens extends Model
...
@@ -185,7 +193,17 @@ class Tokens extends Model
public
function
dictionaryCampaignsEnabledForExternal
()
public
function
dictionaryCampaignsEnabledForExternal
()
{
{
return
$this
->
dictionaryCampaignsForExternal
()
->
enabled
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
();
}
public
function
dictionaryCampaignsEnabledForExternalUpdated
()
{
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
forUpdated
();
}
public
function
dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated
()
{
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
forUpdated
()
->
needUpdated
();
}
}
public
function
dictionaryCampaignsEnabledForNotExternal
()
public
function
dictionaryCampaignsEnabledForNotExternal
()
...
@@ -195,32 +213,27 @@ class Tokens extends Model
...
@@ -195,32 +213,27 @@ class Tokens extends Model
public
function
dictionaryCampaignsNotEnabledForExternalNotDisabled
()
public
function
dictionaryCampaignsNotEnabledForExternalNotDisabled
()
{
{
return
$this
->
dictionaryCampaigns
ForExternal
()
->
enabled
(
false
)
->
notDisabled
();
return
$this
->
dictionaryCampaigns
()
->
enabled
(
false
)
->
forExternal
(
)
->
notDisabled
();
}
}
public
function
dictionaryCampaignsEnabledForExternalDisabled
()
public
function
dictionaryCampaignsEnabledForExternalDisabled
()
{
{
return
$this
->
dictionaryCampaigns
ForExternal
()
->
enabled
()
->
disabled
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
disabled
();
}
}
public
function
dictionaryCampaignsEnabledForExternalSynchronized
()
public
function
dictionaryCampaignsEnabledForExternalSynchronized
()
{
{
return
$this
->
dictionaryCampaignsForExternal
()
->
enabled
()
->
synchronized
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
synchronized
();
}
public
function
dictionaryCampaignsEnabledForExternalSynchronizedNeedUpdated
()
{
return
$this
->
dictionaryCampaignsEnabledForExternalSynchronized
()
->
enabled
()
->
needUpdated
();
}
}
public
function
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
()
public
function
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
()
{
{
return
$this
->
dictionaryCampaigns
EnabledForExternalS
ynchronized
()
->
forUpdatedSelf
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
s
ynchronized
()
->
forUpdatedSelf
();
}
}
public
function
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
()
public
function
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
()
{
{
return
$this
->
dictionaryCampaigns
EnabledForExternalS
ynchronized
()
->
forUpdatedChildren
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
s
ynchronized
()
->
forUpdatedChildren
();
}
}
public
function
campaignsForManaged
()
public
function
campaignsForManaged
()
...
...
app/Models/User.php
View file @
6f86a70
...
@@ -5,6 +5,7 @@ namespace App\Models;
...
@@ -5,6 +5,7 @@ namespace App\Models;
use
Illuminate\Auth\Authenticatable
;
use
Illuminate\Auth\Authenticatable
;
use
Illuminate\Contracts\Auth\Access\Authorizable
as
AuthorizableContract
;
use
Illuminate\Contracts\Auth\Access\Authorizable
as
AuthorizableContract
;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Foundation\Auth\Access\Authorizable
;
use
Illuminate\Foundation\Auth\Access\Authorizable
;
use
Illuminate\Support\Facades\App
;
use
Illuminate\Support\Facades\App
;
...
@@ -87,22 +88,37 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
...
@@ -87,22 +88,37 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
return
$this
->
email
===
'johndoe@example.com'
;
return
$this
->
email
===
'johndoe@example.com'
;
}
}
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeOrderByName
(
$query
)
public
function
scopeOrderByName
(
$query
)
{
{
$query
->
orderBy
(
'last_name'
)
->
orderBy
(
'first_name'
);
return
$query
->
orderBy
(
'last_name'
)
->
orderBy
(
'first_name'
);
}
}
/**
* @param Builder $query
* @param string $role
* @return Builder
*/
public
function
scopeWhereRole
(
$query
,
$role
)
public
function
scopeWhereRole
(
$query
,
$role
)
{
{
switch
(
$role
)
{
switch
(
$role
)
{
case
'user'
:
return
$query
->
where
(
'owner'
,
false
);
case
'user'
:
return
$query
->
where
(
'owner'
,
false
);
case
'owner'
:
return
$query
->
where
(
'owner'
,
true
);
case
'owner'
:
return
$query
->
where
(
'owner'
,
true
);
}
}
return
$query
;
}
}
/**
* @param Builder $query
* @param array $filters
* @return Builder
*/
public
function
scopeFilter
(
$query
,
array
$filters
)
public
function
scopeFilter
(
$query
,
array
$filters
)
{
{
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
return
$query
->
when
(
$filters
[
'search'
]
??
null
,
function
(
$query
,
$search
)
{
$query
->
where
(
function
(
$query
)
use
(
$search
)
{
$query
->
where
(
function
(
$query
)
use
(
$search
)
{
$query
->
where
(
'first_name'
,
'like'
,
'%'
.
$search
.
'%'
)
$query
->
where
(
'first_name'
,
'like'
,
'%'
.
$search
.
'%'
)
->
orWhere
(
'last_name'
,
'like'
,
'%'
.
$search
.
'%'
)
->
orWhere
(
'last_name'
,
'like'
,
'%'
.
$search
.
'%'
)
...
...
app/Models/Variable.php
View file @
6f86a70
...
@@ -59,7 +59,11 @@ class Variable extends Model
...
@@ -59,7 +59,11 @@ class Variable extends Model
return
$variable_list
;
return
$variable_list
;
}
}
public
function
scopeDefaultOrderBy
(
Builder
$query
)
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeDefaultOrderBy
(
$query
)
{
{
return
$query
->
orderBy
(
'name'
);
return
$query
->
orderBy
(
'name'
);
}
}
...
...
app/Service/Requests/Direct/CheckCampaignsChanges.php
View file @
6f86a70
...
@@ -31,7 +31,7 @@ class CheckCampaignsChanges extends DirectRequest
...
@@ -31,7 +31,7 @@ class CheckCampaignsChanges extends DirectRequest
if
(
in_array
(
self
::
SELF
,
$campaign_data
[
'ChangesIn'
])
||
in_array
(
self
::
CHILDREN
,
$campaign_data
[
'ChangesIn'
]))
{
if
(
in_array
(
self
::
SELF
,
$campaign_data
[
'ChangesIn'
])
||
in_array
(
self
::
CHILDREN
,
$campaign_data
[
'ChangesIn'
]))
{
$data
=
[];
$data
=
[];
if
(
in_array
(
self
::
SELF
,
$campaign_data
[
'ChangesIn'
]))
{
if
(
$this
->
getToken
()
->
isMain
()
&&
in_array
(
self
::
SELF
,
$campaign_data
[
'ChangesIn'
]))
{
$data
[
'updated_self'
]
=
Carbon
::
now
();
$data
[
'updated_self'
]
=
Carbon
::
now
();
}
}
...
@@ -52,10 +52,16 @@ class CheckCampaignsChanges extends DirectRequest
...
@@ -52,10 +52,16 @@ class CheckCampaignsChanges extends DirectRequest
}
else
{
}
else
{
$dictionaryCampaign
=
DictionaryCampaign
::
synchronized
()
->
find
(
$external_id
);
$dictionaryCampaign
=
DictionaryCampaign
::
firstWhere
(
'external_id'
,
$external_id
);
if
(
$dictionaryCampaign
)
{
if
(
$dictionaryCampaign
)
{
$data
[
'external_updated_at'
]
=
Carbon
::
now
();
$data
[
'external_updated_at'
]
=
Carbon
::
now
();
if
(
$dictionaryCampaign
->
updated
)
{
$data
[
'updated_need'
]
=
Carbon
::
now
();
}
$dictionaryCampaign
->
update
(
$data
);
$dictionaryCampaign
->
update
(
$data
);
}
}
...
...
app/Service/Requests/Direct/CheckChanges.php
View file @
6f86a70
...
@@ -80,13 +80,14 @@ class CheckChanges extends DirectRequest
...
@@ -80,13 +80,14 @@ class CheckChanges extends DirectRequest
]);
]);
}
}
}
else
{
}
else
{
$goalAdGroup
=
GoalAdGroup
::
where
(
'external_id'
,
$ad_group_id
)
->
first
();
$goalAdGroup
=
GoalAdGroup
::
w
ith
(
'dictionaryCampaign'
)
->
firstW
here
(
'external_id'
,
$ad_group_id
)
->
first
();
if
(
$goalAdGroup
)
{
if
(
$goalAdGroup
&&
$goalAdGroup
->
dictionaryCampaign
&&
$goalAdGroup
->
dictionaryCampaign
->
updated
)
{
$goalAdGroup
->
update
([
$goalAdGroup
->
update
([
'updated_
self
'
=>
Carbon
::
now
(),
'updated_
need
'
=>
Carbon
::
now
(),
]);
]);
}
}
}
}
}
}
...
...
resources/js/Pages/Tokens/Edit.vue
View file @
6f86a70
...
@@ -112,7 +112,7 @@ export default {
...
@@ -112,7 +112,7 @@ export default {
},
},
citySynced
(
city_id
,
campaign_id
,
synced
)
{
citySynced
(
city_id
,
campaign_id
,
synced
)
{
this
.
$inertia
.
post
(
this
.
route
(
'token.city.campaign.synced'
,
[
this
.
token
.
id
,
city_id
,
campaign_id
]),
{
this
.
$inertia
.
post
(
this
.
route
(
'token.city.campaign.synced'
,
[
this
.
token
.
id
,
city_id
,
campaign_id
]),
{
updat
ed
:
synced
?
1
:
0
,
sync
ed
:
synced
?
1
:
0
,
})
})
},
},
cityEnabled
(
city_id
,
campaign_id
,
enabled
)
{
cityEnabled
(
city_id
,
campaign_id
,
enabled
)
{
...
...
tests/Unit/CheckCampaignsTest.php
View file @
6f86a70
...
@@ -147,9 +147,42 @@ class CheckCampaignsTest extends TestCase
...
@@ -147,9 +147,42 @@ class CheckCampaignsTest extends TestCase
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
$this
->
assertEquals
(
true
,
$campaign
->
pivot
->
updated
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
external_updated_at
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
external_updated_at
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
updated_self
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
updated_need
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
updated_children
);
$campaign
->
pivot
->
update
([
'external_updated_at'
=>
null
,
'updated_need'
=>
null
,
'updated'
=>
false
,
]);
$this
->
request
->
handle
([
'result'
=>
[
'Timestamp'
=>
1622459200
,
'Campaigns'
=>
[
[
'ChangesIn'
=>
[
'SELF'
,
'CHILDREN'
],
'CampaignId'
=>
1
]
]
]
]);
$this
->
assertEquals
(
$this
->
request
->
getToken
()
->
check_changes_campaign_at
->
timestamp
,
1622459200
);
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
$this
->
assertEquals
(
false
,
$campaign
->
pivot
->
updated
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
external_updated_at
);
$this
->
assertNull
(
$campaign
->
pivot
->
updated_need
);
$campaign
->
pivot
->
update
([
'updated'
=>
true
,
]);
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
$campaign
->
pivot
->
update
([
$campaign
->
pivot
->
update
([
'external_id'
=>
1
,
'external_id'
=>
1
,
...
...
tests/Unit/LimitsTest.php
View file @
6f86a70
...
@@ -174,7 +174,7 @@ class LimitsTest extends TestCase
...
@@ -174,7 +174,7 @@ class LimitsTest extends TestCase
$requestCmpgn
=
$request
->
getRequest
(
'Campaigns'
,
'update'
);
$requestCmpgn
=
$request
->
getRequest
(
'Campaigns'
,
'update'
);
$this
->
token
->
limit
=
191
;
$this
->
token
->
limit
=
191
;
$requestCmpgn
->
call
([
$requestCmpgn
->
call
([
'dictionaryCampaigns'
=>
$this
->
token
->
dictionaryCampaignsEnabledForExternal
Synchroniz
edNeedUpdated
'dictionaryCampaigns'
=>
$this
->
token
->
dictionaryCampaignsEnabledForExternal
Updat
edNeedUpdated
]);
]);
$objects
=
$this
->
limitService
->
countObjectsLimit
(
$requestCmpgn
);
$objects
=
$this
->
limitService
->
countObjectsLimit
(
$requestCmpgn
);
$this
->
assertEquals
(
$objects
,
0
);
$this
->
assertEquals
(
$objects
,
0
);
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment