public function create() { $dsn = explode('=', Yii::$app->db->dsn); if (!$this->validate()) { return false; } $model = new Site(); $model->attributes = $this->attributes; $model->user_id = Yii::$app->user->id; $model->DB_NAME = $dsn[2]; $model->DB_USER = Yii::$app->db->username; $model->DB_PASSWORD = Yii::$app->db->password; $model->DB_HOST = 'localhost'; $model->DB_CHARSET = 'utf8'; $model->DB_COLLATE = null; $model->AUTH_KEY = Yii::$app->wordpress->generatePassword(); $model->SECURE_AUTH_KEY = Yii::$app->wordpress->generatePassword(); $model->LOGGED_IN_KEY = Yii::$app->wordpress->generatePassword(); $model->NONCE_KEY = Yii::$app->wordpress->generatePassword(); $model->AUTH_SALT = Yii::$app->wordpress->generatePassword(); $model->SECURE_AUTH_SALT = Yii::$app->wordpress->generatePassword(); $model->LOGGED_IN_SALT = Yii::$app->wordpress->generatePassword(); $model->NONCE_SALT = Yii::$app->wordpress->generatePassword(); $model->DB_PREFIX = str_replace(['.'], [], $this->domain) . '_'; $model->WP_DEBUG = null; if ($model->save()) { $queue = new Queue(); $queue->attributes = ['domain_id' => $model->id, 'title' => $this->title, 'admin' => $this->admin, 'password' => $this->password, 'email' => $this->email]; return $queue->save(); } }
/** * Enqueue the message storing it in database. * * @return boolean true on success, false otherwise */ public function queue() { $item = new Queue(); $item->from = serialize($this->getFrom()); $item->to = serialize($this->getTo()); $item->cc = serialize($this->getCc()); $item->bcc = serialize($this->getBcc()); $item->reply_to = serialize($this->getReplyTo()); $item->charset = $this->getCharset(); $item->subject = $this->getSubject(); $item->attachments = serialize($this->attachments); $item->attempts = 0; if ($parts = $this->getSwiftMessage()->getChildren()) { foreach ($parts as $key => $part) { if (!$part instanceof \Swift_Mime_Attachment) { /* @var $part \Swift_Mime_MimePart */ switch ($part->getContentType()) { case 'text/html': $item->html_body = $part->getBody(); break; case 'text/plain': $item->text_body = $part->getBody(); break; } if (!$item->charset) { $item->charset = $part->getCharset(); } } } } return $item->save(); }
/** * Creates a new Queue model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Queue(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * observe Lumen event saved * 1. check if prev day * 2. save into queue * 3. act, accept or refuse * * @param $model * @return bool */ public function saved($model) { //1. check if prev day $date_on = $model->on->startOfDay(); $date_today = Carbon::now()->startOfDay(); if ($date_today->diffInDays($date_on) >= 1 && $model->person()->count()) { //2. save into queue $on = $date_on->format('Y-m-d'); $idle_rule = new Policy(); $idle_rule_1 = $idle_rule->organisationid($model->person->organisation_id)->type('firstidle')->OnDate($on)->orderBy('started_at', 'desc')->first(); $idle_rule_2 = $idle_rule->organisationid($model->person->organisation_id)->type('secondidle')->OnDate($on)->orderBy('started_at', 'desc')->first(); $idle_rule_3 = $idle_rule->organisationid($model->person->organisation_id)->type('thirdidle')->OnDate($on)->orderBy('started_at', 'desc')->first(); $margin_bottom_idle = 900; $idle_1 = 3600; $idle_2 = 7200; if ($idle_rule_1) { $margin_bottom_idle = (int) $idle_rule_1->value; } if ($idle_rule_2) { $idle_1 = (int) $idle_rule_2->value; } if ($idle_rule_3) { $idle_2 = (int) $idle_rule_3->value; } $employee = new Employee(); $employee->workend = $date_on->format('Y-m-d H:i:s'); $employee = count($employee->organisationid($model->person->organisation_id)->get(['id'])); $parameter['margin_bottom_idle'] = $margin_bottom_idle; $parameter['idle_1'] = $idle_1; $parameter['idle_2'] = $idle_2; $parameter['on'] = $on; $parameter['organisation_id'] = $model->person->organisation_id; $check = Queue::where('parameter', json_encode($parameter))->where('process_name', 'hr:logobserver')->where('process_number', '0')->first(); if (!$check) { $queue = new Queue(); $queue->fill(['process_name' => 'hr:logobserver', 'parameter' => json_encode($parameter), 'total_process' => $employee, 'task_per_process' => 1, 'process_number' => 0, 'total_task' => $employee, 'message' => 'Initial Commit']); if (!$queue->save()) { $model['errors'] = $queue->getError(); return false; } else { return true; } } } return true; }
/** * absence log * * @return void * @author **/ public function generate() { Log::info('Running PointExpireQueue Generator command @' . date('Y-m-d H:i:s')); $clients = ClientTemplate::get(); foreach ($clients as $key => $value) { $points = PointLog::debit(true)->onactive([Carbon::parse(' + 1 month')->startOfDay()->format('Y-m-d H:i:s'), Carbon::parse(' + 1 month')->endOfDay()->format('Y-m-d H:i:s')])->haventgetcut(true)->get(); if (count($points) > 0) { $policies = new Store(); $policies = $policies->default(true)->get()->toArray(); $store = []; foreach ($policies as $key => $value2) { $store[$value2['type']] = $value2['value']; } $store['action'] = $store['url'] . '/product'; DB::beginTransaction(); $parameter['store'] = $store; $parameter['template'] = $value['located']; $parameter['on'] = Carbon::parse(' + 1 month')->format('Y-m-d H:i:s'); $queue = new Queue(); $queue->fill(['process_name' => 'point:expire', 'parameter' => json_encode($parameter), 'total_process' => count($points), 'task_per_process' => 1, 'process_number' => 0, 'total_task' => count($points), 'message' => 'Initial Commit']); if (!$queue->save()) { DB::rollback(); Log::error('Save queue on PointExpireQueue command ' . json_encode($queue->getError())); } else { DB::Commit(); } } } return true; }