48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Slack\Jobs;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Slack\Exceptions\SlackTokenScopeException;
|
|
use Slack\Models\Team;
|
|
|
|
class TeamUpdate extends Job
|
|
{
|
|
protected const LOGKEY = 'JTU';
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @param Team $to
|
|
*/
|
|
public function __construct(Team $to)
|
|
{
|
|
$this->_data['to'] = $to;
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
try {
|
|
$response = $this->to->slackAPI()->getTeam($this->to->team_id);
|
|
|
|
} catch (SlackTokenScopeException $e) {
|
|
Log::error(sprintf('%s:%s',self::LOGKEY,$e->getMessage()));
|
|
|
|
return;
|
|
}
|
|
|
|
// We need to refresh the team, in case their status has changed since the job was scheduled.
|
|
$this->to->refresh();
|
|
|
|
$this->to->team_name = $response->domain;
|
|
$this->to->description = $response->name;
|
|
|
|
if ($this->to->isDirty())
|
|
Log::debug(sprintf('%s:Updated [%s] (%s)',self::LOGKEY,$this->to->id,$this->to->team_id),['m'=>__METHOD__,'changed'=>$this->to->getDirty()]);
|
|
else
|
|
Log::debug(sprintf('%s:No Update for [%s] (%s)',self::LOGKEY,$this->to->id,$this->to->user_id),['m'=>__METHOD__]);
|
|
|
|
$this->to->save();
|
|
}
|
|
} |