idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
35,600
protected function parseTemplate ( IncidentTemplate $ template , UpdateIncidentCommand $ command ) { $ env = new Twig_Environment ( new Twig_Loader_Array ( [ ] ) ) ; $ template = $ env -> createTemplate ( $ template -> template ) ; $ vars = array_merge ( $ command -> template_vars , [ 'incident' => [ 'name' => $ comman...
Compiles an incident template into an incident message .
35,601
public function scopeInProgress ( Builder $ query ) { return $ query -> where ( 'scheduled_at' , '<=' , Carbon :: now ( ) ) -> where ( 'status' , '<>' , self :: COMPLETE ) -> where ( function ( $ query ) { $ query -> whereNull ( 'completed_at' ) -> orWhere ( 'completed_at' , '>' , Carbon :: now ( ) ) ; } ) ; }
Scope schedules that are in progress .
35,602
public function scopeFutureSchedules ( $ query ) { return $ query -> whereIn ( 'status' , [ self :: UPCOMING , self :: IN_PROGRESS ] ) -> where ( 'scheduled_at' , '>=' , Carbon :: now ( ) ) ; }
Scopes schedules to those in the future .
35,603
public function handle ( RemoveMetricCommand $ command ) { $ metric = $ command -> metric ; event ( new MetricWasRemovedEvent ( $ this -> auth -> user ( ) , $ metric ) ) ; $ metric -> delete ( ) ; }
Handle the remove metric command .
35,604
public function handle ( SignupUserCommand $ command ) { $ user = User :: create ( [ 'username' => $ command -> username , 'password' => $ command -> password , 'email' => $ command -> email , 'level' => User :: LEVEL_USER , ] ) ; event ( new UserWasCreatedEvent ( $ user ) ) ; return $ user ; }
Handle the signup user command .
35,605
public function avatar ( ) { if ( Config :: get ( 'setting.enable_external_dependencies' ) ) { return sprintf ( 'https://www.gravatar.com/avatar/%s?size=%d' , md5 ( strtolower ( $ this -> email ) ) , 200 ) ; } return Avatar :: create ( $ this -> username ) -> toBase64 ( ) ; }
Returns the users avatar .
35,606
public function handle ( WelcomeUserCommand $ command ) { $ command -> user -> update ( [ 'welcomed' => true ] ) ; event ( new UserWasWelcomedEvent ( $ command -> user ) ) ; }
Handle the welcome user command .
35,607
public function showCreateIncidentUpdateAction ( Incident $ incident ) { return View :: make ( 'dashboard.incidents.updates.add' ) -> withIncident ( $ incident ) -> withNotificationsEnabled ( $ this -> system -> canNotifySubscribers ( ) ) ; }
Shows the incident update form .
35,608
public function createIncidentUpdateAction ( Incident $ incident ) { try { $ incidentUpdate = execute ( new CreateIncidentUpdateCommand ( $ incident , Binput :: get ( 'status' ) , Binput :: get ( 'message' ) , Binput :: get ( 'component_id' ) , Binput :: get ( 'component_status' ) , $ this -> auth -> user ( ) ) ) ; } c...
Creates a new incident update .
35,609
public function editIncidentUpdateAction ( Incident $ incident , IncidentUpdate $ incidentUpdate ) { try { $ incidentUpdate = execute ( new UpdateIncidentUpdateCommand ( $ incidentUpdate , Binput :: get ( 'status' ) , Binput :: get ( 'message' ) , $ this -> auth -> user ( ) ) ) ; } catch ( ValidationException $ e ) { r...
Edit an incident update .
35,610
public function handle ( CreateScheduleCommand $ command ) { try { $ schedule = Schedule :: create ( $ this -> filter ( $ command ) ) ; event ( new ScheduleWasCreatedEvent ( $ this -> auth -> user ( ) , $ schedule ) ) ; } catch ( InvalidArgumentException $ e ) { throw new ValidationException ( new MessageBag ( [ $ e ->...
Handle the create schedule command .
35,611
protected static function convertToTags ( $ values ) { return collect ( $ values ) -> map ( function ( $ value ) { if ( $ value instanceof Tag ) { return $ value ; } return Tag :: where ( 'slug' , '=' , $ value ) -> first ( ) ; } ) ; }
Convert a list of tags into a collection of \ CachetHQ \ Cachet \ Models \ Tag .
35,612
public function getStatus ( ) { $ includePrivate = $ this -> auth -> check ( ) ; $ totalComponents = Component :: enabled ( ) -> authenticated ( $ includePrivate ) -> count ( ) ; $ majorOutages = Component :: enabled ( ) -> authenticated ( $ includePrivate ) -> status ( 4 ) -> count ( ) ; $ majorOutageRate = ( int ) $ ...
Get the entire system status .
35,613
public function canNotifySubscribers ( ) { $ maintenancePeriods = Schedule :: inProgress ( ) -> count ( ) ; if ( $ maintenancePeriods === 0 ) { return true ; } return ! $ this -> config -> get ( 'setting.suppress_notifications_in_maintenance' ) ; }
Determine if Cachet is allowed to send notifications to users subscribers or third party tools .
35,614
public function compose ( View $ view ) { $ enabledLangs = $ this -> config -> get ( 'langs' ) ; $ langs = array_map ( function ( $ lang ) use ( $ enabledLangs ) { $ locale = basename ( $ lang ) ; return [ $ locale => Arr :: get ( $ enabledLangs , $ locale , [ 'name' => $ locale , 'subset' => null , ] ) ] ; } , glob ( ...
Timezones and Locales composer .
35,615
public function handle ( UpdateComponentGroupCommand $ command ) { $ group = $ command -> group ; $ group -> update ( $ this -> filter ( $ command ) ) ; event ( new ComponentGroupWasUpdatedEvent ( $ this -> auth -> user ( ) , $ group ) ) ; return $ group ; }
Handle the update component group command .
35,616
protected function registerMetricRepository ( ) { $ this -> app -> singleton ( MetricRepository :: class , function ( Container $ app ) { $ config = $ app -> make ( ConfigRepository :: class ) ; switch ( $ config -> get ( 'database.default' ) ) { case 'mysql' : $ repository = new MySqlRepository ( $ config ) ; break ; ...
Register the metric repository .
35,617
public function map ( Registrar $ router ) { $ router -> group ( [ 'middleware' => [ 'auth' ] , 'namespace' => 'Dashboard' , 'prefix' => 'dashboard/incidents' , ] , function ( Registrar $ router ) { $ router -> get ( '/' , [ 'as' => 'get:dashboard.incidents' , 'uses' => 'IncidentController@showIncidents' , ] ) ; $ rout...
Define the dashboard incident routes .
35,618
public function index ( ) { $ groups = ComponentGroup :: query ( ) ; if ( ! $ this -> guard -> check ( ) ) { $ groups = ComponentGroup :: visible ( ) ; } $ groups -> search ( Binput :: except ( [ 'sort' , 'order' , 'per_page' ] ) ) ; if ( $ sortBy = Binput :: get ( 'sort' ) ) { $ direction = Binput :: get ( 'order' , '...
Get all groups .
35,619
public function store ( ) { try { $ group = execute ( new CreateComponentGroupCommand ( Binput :: get ( 'name' ) , Binput :: get ( 'order' , 0 ) , Binput :: get ( 'collapsed' , 0 ) , Binput :: get ( 'visible' , ComponentGroup :: VISIBLE_AUTHENTICATED ) ) ) ; } catch ( QueryException $ e ) { throw new BadRequestHttpExce...
Create a new component group .
35,620
public function update ( ComponentGroup $ group ) { try { $ group = execute ( new UpdateComponentGroupCommand ( $ group , Binput :: get ( 'name' ) , Binput :: get ( 'order' ) , Binput :: get ( 'collapsed' ) , Binput :: get ( 'visible' ) ) ) ; } catch ( QueryException $ e ) { throw new BadRequestHttpException ( ) ; } re...
Update an existing group .
35,621
protected function getQueryType ( Metric $ metric ) { if ( ! isset ( $ metric -> calc_type ) || $ metric -> calc_type == Metric :: CALC_SUM ) { return "sum({$this->getMetricPointsTable()}.value * {$this->getMetricPointsTable()}.counter) AS value" ; } elseif ( $ metric -> calc_type == Metric :: CALC_AVG ) { return "avg(...
Return the query type .
35,622
protected function mapResults ( Metric $ metric , array $ results ) { $ results = Collection :: make ( $ results ) ; return $ results -> map ( function ( $ point ) use ( $ metric ) { if ( ! $ point -> value ) { $ point -> value = $ metric -> default_value ; } if ( $ point -> value === 0 && $ metric -> default_value != ...
Map the result set .
35,623
public function postSubscribe ( ) { $ email = Binput :: get ( 'email' ) ; $ subscriptions = Binput :: get ( 'subscriptions' ) ; $ verified = app ( Repository :: class ) -> get ( 'setting.skip_subscriber_verification' ) ; try { $ subscription = execute ( new SubscribeSubscriberCommand ( $ email , $ verified ) ) ; } catc...
Handle the subscribe user .
35,624
public function getVerify ( $ code = null ) { if ( $ code === null ) { throw new NotFoundHttpException ( ) ; } $ subscriber = Subscriber :: where ( 'verify_code' , '=' , $ code ) -> first ( ) ; if ( ! $ subscriber ) { throw new BadRequestHttpException ( ) ; } if ( ! $ subscriber -> is_verified ) { execute ( new VerifyS...
Handle the verify subscriber email .
35,625
public function getUnsubscribe ( $ code = null , $ subscription = null ) { if ( $ code === null ) { throw new NotFoundHttpException ( ) ; } $ subscriber = Subscriber :: where ( 'verify_code' , '=' , $ code ) -> first ( ) ; if ( ! $ subscriber || ! $ subscriber -> is_verified ) { throw new BadRequestHttpException ( ) ; ...
Handle the unsubscribe .
35,626
public function showManage ( $ code = null ) { if ( $ code === null ) { throw new NotFoundHttpException ( ) ; } $ includePrivate = $ this -> auth -> check ( ) ; $ subscriber = Subscriber :: where ( 'verify_code' , '=' , $ code ) -> first ( ) ; $ usedComponentGroups = Component :: enabled ( ) -> authenticated ( $ includ...
Shows the subscription manager page .
35,627
public function postManage ( $ code = null ) { if ( $ code === null ) { throw new NotFoundHttpException ( ) ; } $ subscriber = Subscriber :: where ( 'verify_code' , '=' , $ code ) -> first ( ) ; if ( ! $ subscriber ) { throw new BadRequestHttpException ( ) ; } try { execute ( new UpdateSubscriberSubscriptionCommand ( $...
Updates the subscription manager for a subscriber .
35,628
public function handle ( CreateUserCommand $ command ) { $ user = User :: create ( [ 'username' => $ command -> username , 'password' => $ command -> password , 'email' => $ command -> email , 'level' => $ command -> level , ] ) ; event ( new UserWasCreatedEvent ( $ user ) ) ; return $ user ; }
Handle the add user command .
35,629
public function handle ( UpdateScheduleCommand $ command ) { $ schedule = $ command -> schedule ; $ schedule -> update ( $ this -> filter ( $ command ) ) ; event ( new ScheduleWasUpdatedEvent ( $ this -> auth -> user ( ) , $ schedule ) ) ; return $ schedule ; }
Handle the update schedule command .
35,630
public function completed_at_datetimepicker ( ) { if ( $ this -> wrappedObject -> completed_at ) { return $ this -> dates -> make ( $ this -> wrappedObject -> completed_at ) -> format ( 'Y-m-d H:i' ) ; } }
Formats the completed_at time ready to be used by bootstrap - datetimepicker .
35,631
public function handle ( CreateComponentCommand $ command ) { $ component = Component :: create ( $ this -> filter ( $ command ) ) ; event ( new ComponentWasCreatedEvent ( $ this -> auth -> user ( ) , $ component ) ) ; return $ component ; }
Handle the add component command .
35,632
public function send ( ) { if ( ! $ this -> enabled ( ) ) { return ; } $ setting = app ( Setting :: class ) ; if ( ! $ installId = $ setting -> get ( 'install_id' , null ) ) { $ installId = sha1 ( Str :: random ( 20 ) ) ; $ setting -> set ( 'install_id' , $ installId ) ; } $ payload = [ 'install_id' => $ installId , 'v...
Send a beacon to our server .
35,633
protected function configureEnvironmentFile ( ) { $ dir = app ( ) -> environmentPath ( ) ; $ file = app ( ) -> environmentFile ( ) ; $ path = "{$dir}/{$file}" ; if ( file_exists ( $ path ) ) { $ this -> line ( 'Environment file already exists. Moving on.' ) ; return ; } copy ( "$path.example" , $ path ) ; }
Copy the environment file .
35,634
protected function configureDatabase ( array $ default = [ ] ) { $ config = array_merge ( [ 'DB_DRIVER' => null , 'DB_HOST' => null , 'DB_DATABASE' => null , 'DB_USERNAME' => null , 'DB_PASSWORD' => null , 'DB_PORT' => null , 'DB_PREFIX' => null , ] , $ default ) ; $ config [ 'DB_DRIVER' ] = $ this -> choice ( 'Which d...
Configure the database .
35,635
protected function configureDrivers ( array $ default = [ ] ) { $ config = array_merge ( [ 'CACHE_DRIVER' => null , 'SESSION_DRIVER' => null , 'QUEUE_DRIVER' => null , ] , $ default ) ; $ this -> formatConfigsTable ( $ config ) ; $ config [ 'CACHE_DRIVER' ] = $ this -> choice ( 'Which cache driver do you want to use?' ...
Configure other drivers .
35,636
protected function configureMail ( array $ config = [ ] ) { $ config = array_merge ( [ 'MAIL_DRIVER' => null , 'MAIL_HOST' => null , 'MAIL_PORT' => null , 'MAIL_USERNAME' => null , 'MAIL_PASSWORD' => null , 'MAIL_ADDRESS' => null , 'MAIL_NAME' => null , 'MAIL_ENCRYPTION' => null , ] , $ config ) ; if ( ! $ this -> conf...
Configure mail .
35,637
protected function configureCachet ( array $ config = [ ] ) { $ config = [ ] ; if ( $ this -> confirm ( 'Do you wish to use Cachet Beacon?' ) ) { $ config [ 'CACHET_BEACON' ] = 'true' ; } if ( $ this -> confirm ( 'Do you wish to use Emoji? This requires a GitHub oAuth Token!' ) ) { $ config [ 'GITHUB_TOKEN' ] = $ this ...
Configure Cachet .
35,638
protected function configureUser ( ) { if ( ! $ this -> confirm ( 'Do you want to create an admin user?' ) ) { return ; } $ this -> getFreshConfiguration ( ) ; $ user = [ 'username' => $ this -> ask ( 'Please enter your username' ) , 'email' => $ this -> ask ( 'Please enter your email' ) , 'password' => $ this -> secre...
Configure the first user .
35,639
protected function configureRedis ( ) { $ config = [ 'REDIS_HOST' => null , 'REDIS_DATABASE' => null , 'REDIS_PORT' => null , ] ; $ config [ 'REDIS_HOST' ] = $ this -> ask ( 'What is the host of your redis server?' ) ; $ config [ 'REDIS_DATABASE' ] = $ this -> ask ( 'What is the name of the database that Cachet should ...
Configure the redis connection .
35,640
protected function formatConfigsTable ( array $ config ) { $ configRows = [ ] ; foreach ( $ config as $ setting => $ value ) { $ configRows [ ] = compact ( 'setting' , 'value' ) ; } $ this -> table ( [ 'Setting' , 'Value' ] , $ configRows ) ; }
Format the configs into a pretty table that we can easily read .
35,641
public function showTeamView ( ) { $ team = User :: all ( ) ; return View :: make ( 'dashboard.team.index' ) -> withPageTitle ( trans ( 'dashboard.team.team' ) . ' - ' . trans ( 'dashboard.dashboard' ) ) -> withTeamMembers ( $ team ) ; }
Shows the team members view .
35,642
public function showTeamMemberView ( User $ user ) { return View :: make ( 'dashboard.team.edit' ) -> withPageTitle ( trans ( 'dashboard.team.edit.title' ) . ' - ' . trans ( 'dashboard.dashboard' ) ) -> withUser ( $ user ) ; }
Shows the edit team member view .
35,643
protected function paginator ( Paginator $ paginator , Request $ request ) { foreach ( $ request -> query as $ key => $ value ) { if ( $ key != 'page' ) { $ paginator -> appends ( $ key , $ value ) ; } } $ pagination = [ 'pagination' => [ 'total' => ( int ) $ paginator -> total ( ) , 'count' => count ( $ paginator -> i...
Respond with a pagination response .
35,644
protected function respond ( ) { $ response = [ ] ; if ( ! empty ( $ this -> meta ) ) { $ response [ 'meta' ] = $ this -> meta ; } $ response [ 'data' ] = $ this -> data ; if ( $ this -> data instanceof Arrayable ) { $ response [ 'data' ] = $ this -> data -> toArray ( ) ; } return Response :: json ( $ response , $ this...
Build the response .
35,645
public function getTimezone ( ) { $ dateTime = new Date ( ) ; $ dateTime -> setTimeZone ( new DateTimeZone ( $ this -> cachetTimezone ) ) ; return $ dateTime -> format ( 'T' ) ; }
Return the abbreviated timezone .
35,646
public function compose ( View $ view ) { $ view -> withAboutApp ( Markdown :: convertToHtml ( $ this -> config -> get ( 'setting.app_about' ) ) ) ; $ view -> withAppAnalytics ( $ this -> config -> get ( 'setting.app_analytics' ) ) ; $ view -> withAppAnalyticsGoSquared ( $ this -> config -> get ( 'setting.app_analytics...
Index page view composer .
35,647
public function index ( Incident $ incident ) { $ updates = $ incident -> updates ( ) -> orderBy ( 'created_at' , 'desc' ) ; if ( $ sortBy = Binput :: get ( 'sort' ) ) { $ direction = Binput :: has ( 'order' ) && Binput :: get ( 'order' ) == 'desc' ; $ updates -> sort ( $ sortBy , $ direction ) ; } $ updates = $ update...
Return all updates on the incident .
35,648
public function update ( Incident $ incident , IncidentUpdate $ update ) { try { $ update = execute ( new UpdateIncidentUpdateCommand ( $ update , Binput :: get ( 'status' ) , Binput :: get ( 'message' ) , Auth :: user ( ) ) ) ; } catch ( QueryException $ e ) { throw new BadRequestHttpException ( ) ; } return $ this ->...
Update an incident update .
35,649
public function index ( ) { $ templates = IncidentTemplate :: query ( ) ; if ( $ sortBy = Binput :: get ( 'sort' ) ) { $ direction = Binput :: has ( 'order' ) && Binput :: get ( 'order' ) == 'desc' ; $ templates -> sort ( $ sortBy , $ direction ) ; } $ templates = $ templates -> paginate ( Binput :: get ( 'per_page' , ...
Get all incident templates .
35,650
public function scopeIsVerifiedForComponent ( Builder $ query , $ component_id ) { return $ query -> select ( 'subscriptions.*' ) -> join ( 'subscribers' , 'subscriptions.subscriber_id' , '=' , 'subscribers.id' ) -> where ( function ( $ query ) { $ query -> where ( 'subscriptions.component_id' , '=' , $ component_id ) ...
Finds all verified subscriptions for a component .
35,651
public function bind ( Router $ router ) { $ router -> model ( 'component' , 'CachetHQ\Cachet\Models\Component' ) ; $ router -> model ( 'component_group' , 'CachetHQ\Cachet\Models\ComponentGroup' ) ; $ router -> model ( 'incident' , 'CachetHQ\Cachet\Models\Incident' ) ; $ router -> model ( 'incident_template' , 'Cachet...
Define the bindings for the application .
35,652
protected function mapForBrowser ( Router $ router , $ routes , $ applyAlwaysAuthenticate ) { $ middleware = [ EncryptCookies :: class , AddQueuedCookiesToResponse :: class , StartSession :: class , ShareErrorsFromSession :: class , VerifyCsrfToken :: class , SubstituteBindings :: class , ] ; if ( $ applyAlwaysAuthenti...
Wrap the routes in the browser specific middleware .
35,653
protected function mapOtherwise ( Router $ router , $ routes , $ applyAlwaysAuthenticate ) { $ middleware = [ SubstituteBindings :: class , Acceptable :: class , Timezone :: class , ] ; if ( $ applyAlwaysAuthenticate && ! $ this -> isWhiteListedAuthRoute ( $ routes ) ) { $ middleware [ ] = 'auth.api:true' ; } $ router ...
Wrap the routes in the basic middleware .
35,654
private function isWhiteListedAuthRoute ( $ routes ) { foreach ( $ this -> whitelistedAuthRoutes as $ whitelistedRoute ) { if ( is_a ( $ routes , $ whitelistedRoute ) ) { return true ; } } return false ; }
Validates if the route object is an instance of the whitelisted routes . A small workaround since we cant use multiple classes in a instanceof comparison .
35,655
public function handle ( ClaimInviteCommand $ command ) { $ invite = $ command -> invite ; $ invite -> update ( [ 'claimed_at' => Carbon :: now ( ) ] ) ; event ( new InviteWasClaimedEvent ( $ invite ) ) ; }
Handle the claim invite command .
35,656
public function handle ( RemoveIncidentCommand $ command ) { $ incident = $ command -> incident ; event ( new IncidentWasRemovedEvent ( $ this -> auth -> user ( ) , $ incident ) ) ; $ incident -> delete ( ) ; }
Handle the remove incident command .
35,657
public function handle ( RemoveIncidentUpdateCommand $ command ) { $ update = $ command -> incidentUpdate ; event ( new IncidentUpdateWasRemovedEvent ( $ this -> auth -> user ( ) , $ update ) ) ; $ update -> delete ( ) ; }
Handle the remove incident update command .
35,658
public function handle ( ActionInterface $ event ) { $ data = $ event -> getAction ( ) ; $ action = [ 'class_name' => get_class ( $ event ) , 'user_id' => $ data [ 'user' ] -> id , 'username' => $ data [ 'user' ] -> username , 'description' => $ data [ 'description' ] , ] ; if ( isset ( $ data [ 'information' ] ) ) { $...
Handle the any actions that need storing .
35,659
public function handle ( RemoveUserCommand $ command ) { $ user = $ command -> user ; event ( new UserWasRemovedEvent ( $ user ) ) ; $ user -> delete ( ) ; }
Handle the remove user command .
35,660
public function handle ( CreateIncidentUpdateCommand $ command ) { $ data = [ 'incident_id' => $ command -> incident -> id , 'status' => $ command -> status , 'message' => $ command -> message , 'user_id' => $ command -> user -> id , ] ; $ update = IncidentUpdate :: create ( $ data ) ; execute ( new UpdateIncidentComma...
Handle the report incident command .
35,661
public function createSubscriberAction ( ) { $ verified = app ( Repository :: class ) -> get ( 'setting.skip_subscriber_verification' ) ; try { $ subscribers = preg_split ( "/\r\n|\n|\r/" , Binput :: get ( 'email' ) ) ; foreach ( $ subscribers as $ subscriber ) { execute ( new SubscribeSubscriberCommand ( $ subscriber ...
Creates a new subscriber .
35,662
public function map ( Registrar $ router ) { $ router -> group ( [ 'namespace' => 'Api' , 'prefix' => 'api/v1' , ] , function ( Registrar $ router ) { $ router -> group ( [ 'middleware' => [ 'auth.api' , 'cors' ] ] , function ( Registrar $ router ) { $ router -> get ( 'components' , 'ComponentController@index' ) ; $ ro...
Define the api routes .
35,663
public function store ( $ env , array $ data ) { $ this -> files -> put ( $ this -> path ( $ env ) , '<?php return ' . var_export ( $ data , true ) . ';' . PHP_EOL ) ; }
Store the settings in the cache .
35,664
public function load ( $ env ) { try { return $ this -> files -> getRequire ( $ this -> path ( $ env ) ) ; } catch ( Exception $ e ) { return false ; } }
Load the settings from the cache .
35,665
public function handle ( CreateMetricPointCommand $ command ) { $ metric = $ command -> metric ; $ createdAt = $ command -> created_at ; $ point = $ this -> findOrCreatePoint ( $ command ) ; $ point -> increment ( 'counter' , 1 ) ; event ( new MetricPointWasCreatedEvent ( $ this -> auth -> user ( ) , $ point ) ) ; retu...
Handle the add metric point command .
35,666
protected function findOrCreatePoint ( CreateMetricPointCommand $ command ) { $ buffer = Carbon :: now ( ) -> subMinutes ( $ command -> metric -> threshold - 1 ) -> startOfMinute ( ) ; if ( $ point = MetricPoint :: where ( 'metric_id' , '=' , $ command -> metric -> id ) -> where ( 'value' , '=' , $ command -> value ) -...
Find or create a metric point .
35,667
public function handle ( DeleteScheduleCommand $ command ) { $ schedule = $ command -> schedule ; event ( new ScheduleWasRemovedEvent ( $ this -> auth -> user ( ) , $ schedule ) ) ; $ schedule -> delete ( ) ; }
Handle the delete schedule command .
35,668
protected function seedComponentGroups ( ) { $ defaultGroups = [ [ 'name' => 'Websites' , 'order' => 1 , 'collapsed' => 0 , 'visible' => ComponentGroup :: VISIBLE_AUTHENTICATED , ] , [ 'name' => 'Alt Three' , 'order' => 2 , 'collapsed' => 1 , 'visible' => ComponentGroup :: VISIBLE_GUEST , ] , ] ; ComponentGroup :: trun...
Seed the component groups table .
35,669
protected function seedComponents ( ) { $ defaultComponents = [ [ 'name' => 'API' , 'description' => 'Used by third-parties to connect to us' , 'status' => 1 , 'order' => 0 , 'group_id' => 0 , 'link' => '' , ] , [ 'name' => 'Documentation' , 'description' => 'Kindly powered by Readme.io' , 'status' => 1 , 'order' => 0 ...
Seed the components table .
35,670
protected function seedIncidents ( ) { $ incidentMessage = <<<'EINCIDENT'# Of course it does!What kind of web application doesn't these days?## Headers are fun aren't theyIt's _exactly_ why we need Markdown. For **emphasis** and such.EINCIDENT ; $ defaultIncidents = [ [ 'name' => 'Our monkeys aren\'t performing' , 'me...
Seed the incidents table .
35,671
protected function seedIncidentUpdates ( $ incident ) { $ defaultUpdates = [ 1 => [ [ 'status' => Incident :: FIXED , 'message' => 'The monkeys are back and rested!' , 'user_id' => 1 , ] , [ 'status' => Incident :: WATCHED , 'message' => 'Our monkeys need a break from performing. They\'ll be back after a good rest.' , ...
Seed the incident updates table for a given incident .
35,672
protected function seedMetrics ( ) { $ defaultMetrics = [ [ 'name' => 'Cups of coffee' , 'suffix' => 'Cups' , 'description' => 'How many cups of coffee we\'ve drank.' , 'default_value' => 0 , 'calc_type' => 1 , 'display_chart' => 1 , ] , ] ; Metric :: truncate ( ) ; foreach ( $ defaultMetrics as $ metric ) { Metric :: ...
Seed the metrics table .
35,673
protected function seedSchedules ( ) { $ defaultSchedules = [ [ 'name' => 'Demo resets every half hour!' , 'message' => 'You can schedule downtime for _your_ service!' , 'status' => Schedule :: UPCOMING , 'scheduled_at' => ( new DateTime ( ) ) -> add ( new DateInterval ( 'PT2H' ) ) , ] , ] ; Schedule :: truncate ( ) ; ...
Seed the schedules table .
35,674
protected function seedSettings ( ) { $ defaultSettings = [ [ 'key' => 'app_name' , 'value' => 'Cachet Demo' , ] , [ 'key' => 'app_domain' , 'value' => 'https://demo.cachethq.io' , ] , [ 'key' => 'show_support' , 'value' => '1' , ] , [ 'key' => 'app_locale' , 'value' => 'en' , ] , [ 'key' => 'app_timezone' , 'value' =>...
Seed the settings table .
35,675
protected function seedUsers ( ) { $ users = [ [ 'username' => 'test' , 'password' => 'test123' , 'email' => 'test@example.com' , 'level' => User :: LEVEL_ADMIN , 'api_key' => '9yMHsdioQosnyVK4iCVR' , ] , ] ; User :: truncate ( ) ; foreach ( $ users as $ user ) { User :: create ( $ user ) ; } }
Seed the users table .
35,676
public function handle ( CreateComponentGroupCommand $ command ) { $ group = ComponentGroup :: create ( [ 'name' => $ command -> name , 'order' => $ command -> order , 'collapsed' => $ command -> collapsed , 'visible' => $ command -> visible , ] ) ; event ( new ComponentGroupWasCreatedEvent ( $ this -> auth -> user ( )...
Handle the create component group command .
35,677
public function index ( ) { $ metrics = Metric :: query ( ) ; if ( $ sortBy = Binput :: get ( 'sort' ) ) { $ direction = Binput :: has ( 'order' ) && Binput :: get ( 'order' ) == 'desc' ; $ metrics -> sort ( $ sortBy , $ direction ) ; } $ metrics = $ metrics -> paginate ( Binput :: get ( 'per_page' , 20 ) ) ; return $ ...
Get all metrics .
35,678
public function store ( ) { try { $ metric = execute ( new CreateMetricCommand ( Binput :: get ( 'name' ) , Binput :: get ( 'suffix' ) , Binput :: get ( 'description' ) , Binput :: get ( 'default_value' ) , Binput :: get ( 'calc_type' , 0 ) , Binput :: get ( 'display_chart' , true ) , Binput :: get ( 'places' , 2 ) , B...
Create a new metric .
35,679
public function update ( Metric $ metric ) { try { $ metric = execute ( new UpdateMetricCommand ( $ metric , Binput :: get ( 'name' ) , Binput :: get ( 'suffix' ) , Binput :: get ( 'description' ) , Binput :: get ( 'default_value' ) , Binput :: get ( 'calc_type' ) , Binput :: get ( 'display_chart' ) , Binput :: get ( '...
Update an existing metric .
35,680
public function getPointsSinceMinutes ( Metric $ metric , $ minutes ) { $ queryType = $ this -> getQueryType ( $ metric ) ; $ points = DB :: select ( "SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%Y-%m-%d %H:%i') AS `key`, {$queryType} " . "FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetr...
Returns metrics since given minutes .
35,681
public function getPointsSinceHour ( Metric $ metric , $ hour ) { $ queryType = $ this -> getQueryType ( $ metric ) ; $ points = DB :: select ( "SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%Y-%m-%d %H:00') AS `key`, {$queryType} " . "FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPoin...
Returns metrics since given hour .
35,682
public function getPointsSinceDay ( Metric $ metric , $ day ) { $ queryType = $ this -> getQueryType ( $ metric ) ; $ points = DB :: select ( "SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%Y-%m-%d') AS `key`, {$queryType} " . "FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable(...
Returns metrics since given day .
35,683
public function storeMeta ( $ metaData , $ metaType , $ metaId , $ metaModel = Meta :: class ) { if ( ! is_array ( $ metaData ) ) { return ; } foreach ( $ metaData as $ key => $ value ) { $ modelInstance = call_user_func ( [ $ metaModel , 'firstOrNew' ] , [ 'key' => $ key , 'meta_type' => $ metaType , 'meta_id' => $ me...
Stores all Meta values of a model .
35,684
protected function removeEmptyValues ( $ values ) { if ( ! is_array ( $ values ) ) { return empty ( $ values ) ? null : $ values ; } foreach ( $ values as $ key => $ value ) { if ( ! empty ( $ value ) ) { continue ; } unset ( $ values [ $ key ] ) ; } return $ values ; }
Determine if a Value is empty .
35,685
public function postUpdateComponent ( Component $ component ) { try { execute ( new UpdateComponentCommand ( $ component , $ component -> name , $ component -> description , Binput :: get ( 'status' ) , $ component -> link , $ component -> order , $ component -> group_id , $ component -> enabled , $ component -> meta ,...
Updates a component with the entered info .
35,686
public function postUpdateComponentOrder ( ) { $ componentData = Binput :: get ( 'ids' ) ; foreach ( $ componentData as $ order => $ componentId ) { try { $ component = Component :: find ( $ componentId ) ; execute ( new UpdateComponentCommand ( $ component , $ component -> name , $ component -> description , $ compone...
Updates a components ordering .
35,687
public function postUpdateComponentGroupOrder ( ) { $ groupData = Binput :: get ( 'ids' ) ; foreach ( $ groupData as $ order => $ groupId ) { $ group = ComponentGroup :: find ( $ groupId ) ; execute ( new UpdateComponentGroupCommand ( $ group , $ group -> name , $ order + 1 , $ group -> collapsed , $ group -> visible )...
Updates the order of component groups .
35,688
public function getIncidentTemplate ( ) { $ templateSlug = Binput :: get ( 'slug' ) ; if ( $ template = IncidentTemplate :: where ( 'slug' , '=' , $ templateSlug ) -> first ( ) ) { return $ template ; } throw new ModelNotFoundException ( "Incident template for $templateSlug could not be found." ) ; }
Returns a template by slug .
35,689
public function index ( ) { $ incidentVisibility = app ( Guard :: class ) -> check ( ) ? 0 : 1 ; $ incidents = Incident :: where ( 'visible' , '>=' , $ incidentVisibility ) ; $ incidents -> search ( Binput :: except ( [ 'sort' , 'order' , 'per_page' ] ) ) ; if ( $ sortBy = Binput :: get ( 'sort' ) ) { $ direction = Bin...
Get all incidents .
35,690
public function store ( ) { try { $ incident = execute ( new CreateIncidentCommand ( Binput :: get ( 'name' ) , Binput :: get ( 'status' ) , Binput :: get ( 'message' , null , false , false ) , ( bool ) Binput :: get ( 'visible' , true ) , Binput :: get ( 'component_id' ) , Binput :: get ( 'component_status' ) , ( bool...
Create a new incident .
35,691
public function update ( Incident $ incident ) { try { $ incident = execute ( new UpdateIncidentCommand ( $ incident , Binput :: get ( 'name' ) , Binput :: get ( 'status' ) , Binput :: get ( 'message' ) , ( bool ) Binput :: get ( 'visible' , true ) , Binput :: get ( 'component_id' ) , Binput :: get ( 'component_status'...
Update an existing incident .
35,692
public function handle ( SendBeaconJob $ job ) { if ( ! $ this -> beacon -> enabled ( ) ) { return ; } try { $ this -> beacon -> send ( ) ; } catch ( Exception $ e ) { } }
Handle the send beacon job .
35,693
public function handle ( RemoveComponentGroupCommand $ command ) { $ group = $ command -> group ; event ( new ComponentGroupWasRemovedEvent ( $ this -> auth -> user ( ) , $ group ) ) ; $ group -> components -> map ( function ( $ component ) { $ component -> update ( [ 'group_id' => 0 ] ) ; } ) ; $ group -> delete ( ) ;...
Handle the remove component group command .
35,694
public function handle ( UpdateMetricCommand $ command ) { $ metric = $ command -> metric ; $ metric -> update ( $ this -> filter ( $ command ) ) ; event ( new MetricWasUpdatedEvent ( $ this -> auth -> user ( ) , $ metric ) ) ; return $ metric ; }
Handle the update metric command .
35,695
public function version ( ) { $ latest = app ( ) -> make ( Releases :: class ) -> latest ( ) ; return $ this -> setMetaData ( [ 'on_latest' => version_compare ( CACHET_VERSION , $ latest [ 'tag_name' ] ) === 1 , 'latest' => $ latest , ] ) -> item ( CACHET_VERSION ) ; }
Endpoint to show the Cachet version .
35,696
public function status ( ) { $ system = app ( ) -> make ( System :: class ) -> getStatus ( ) ; return $ this -> item ( [ 'status' => $ system [ 'system_status' ] , 'message' => $ system [ 'system_message' ] , ] ) ; }
Get the system status message .
35,697
public function postLogin ( ) { $ loginData = Binput :: only ( [ 'username' , 'password' , 'remember_me' ] ) ; $ loginKey = filter_var ( $ loginData [ 'username' ] , FILTER_VALIDATE_EMAIL ) ? 'email' : 'username' ; $ loginData [ $ loginKey ] = Arr :: pull ( $ loginData , 'username' ) ; $ rememberUser = Arr :: pull ( $ ...
Logs the user in .
35,698
public function postTwoFactor ( ) { if ( $ userId = Session :: pull ( '2fa_id' ) ) { $ code = str_replace ( ' ' , '' , Binput :: get ( 'code' ) ) ; Auth :: loginUsingId ( $ userId ) ; $ user = Auth :: user ( ) ; $ valid = Google2FA :: verifyKey ( $ user -> google_2fa_secret , $ code ) ; if ( $ valid ) { event ( new Use...
Validates the Two Factor token .
35,699
protected function registerDateFactory ( ) { $ this -> app -> singleton ( DateFactory :: class , function ( $ app ) { $ appTimezone = $ app [ 'config' ] -> get ( 'app.timezone' ) ; $ cacheTimezone = $ app [ 'config' ] -> get ( 'cachet.timezone' ) ; return new DateFactory ( $ appTimezone , $ cacheTimezone ) ; } ) ; }
Register the date factory .