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(); }
/** * update 1st version * * @return void * @author **/ public function pointexpire($id) { $queue = new Queue(); $pending = $queue->find($id); $parameters = json_decode($pending->parameter, true); $messages = json_decode($pending->message, true); $errors = new MessageBag(); //check point expire on that day that havent get cut by transaction (or even left over) $points = PointLog::debit(true)->onactive([Carbon::parse($parameters['on'])->startOfDay()->format('Y-m-d H:i:s'), Carbon::parse($parameters['on'])->endOfDay()->format('Y-m-d H:i:s')])->haventgetcut(true)->with(['user'])->get()->toArray(); foreach ($points as $idx => $point) { //1. Check tag/category viewed $stat = \App\Models\StatUserView::userid($point['user_id'])->statabletype(['App\\Models\\Category', 'App\\Models\\Tag'])->get(['statable_id'])->toArray(); //1b. Get slugs $slugs = []; $purchased_prods = []; $purchased_varians = []; foreach ($stat as $key => $value) { $slugs[] = \App\Models\Cluster::find($value['statable_id'])['slug']; } $purchased = \App\Models\TransactionDetail::TransactionSellOn(['paid', 'packed', 'shipping', 'delivered'])->where('transactions.user_id', $point['user_id'])->groupby('varian_id')->with(['varian', 'varian.product', 'varian.product.clusters'])->get()->toArray(); foreach ($purchased as $key => $value) { //2. Check tag/category purchased foreach ($value['varian']['product']['clusters'] as $key2 => $value2) { $slugs[] = $value2['slug']; } $purchased_prods[] = $value['varian']['product_id']; $purchased_varians[] = $value['varian']['size']; } //2a. get slug of category/tag //2b. get product id //2c. get varian size $slug = array_unique($slugs); $productids = array_unique($purchased_prods); $variansize = array_unique($purchased_varians); $result = \App\Models\Product::sellable(true); if (!empty($slug)) { $result = $result->clustersslug($slug); } if (!empty($productids)) { $result = $result->notid($productids); } if (!empty($variansize)) { $result = $result->variansize($variansize); } $product = $result->orderby('price', 'desc')->take(4)->get()->toArray(); $data = ['point' => $point, 'balin' => $parameters['store'], 'product' => $product]; //send mail Mail::send('mail.' . $parameters['template'] . '.crm.point', ['data' => $data], function ($message) use($point, $parameters) { $message->to($point['user']['email'], $point['user']['name'])->subject(strtoupper($parameters['template']) . ' - POINT REMINDER'); }); $pnumber = $pending->process_number + 1; $messages['message'][$pnumber] = 'Sukses Mengirim Email ' . (isset($point['user']['name']) ? $point['user']['name'] : ''); $pending->fill(['process_number' => $pnumber, 'message' => json_encode($messages)]); $pending->save(); } return true; }
public function run() { DB::table('Queues')->delete(); Queue::create(['start_time' => date("H:i:s", time()), 'end_time' => date("H:i:s", time()), 'date' => date('Y-m-d H:i:s'), 'register_key' => 1234, 'user_name' => 'Andrew', 'user_personal_key' => '', 'is_real_queue' => false, 'is_admin_record' => false, 'created_at' => date("Y-m-d H:i:s", time()), 'updated_at' => date("Y-m-d H:i:s", time())]); Queue::create(['start_time' => date("H:i:s", time()), 'end_time' => date("H:i:s", time()), 'date' => date('Y-m-d H:i:s'), 'register_key' => 4455, 'user_name' => 'Bodia', 'user_personal_key' => '', 'is_real_queue' => false, 'is_admin_record' => false, 'created_at' => date("Y-m-d H:i:s", time()), 'updated_at' => date("Y-m-d H:i:s", time())]); Queue::create(['start_time' => date("H:i:s", time()), 'end_time' => date("H:i:s", time()), 'date' => date('Y-m-d H:i:s'), 'register_key' => 7513, 'user_name' => 'WWW', 'user_personal_key' => '', 'is_real_queue' => true, 'is_admin_record' => true, 'created_at' => date("Y-m-d H:i:s", time()), 'updated_at' => date("Y-m-d H:i:s", time())]); }
/** * update 1st version * * @return void * @author **/ public function checkpendingjobs() { set_time_limit(0); $queue = new Queue(); $pendings = $queue->running(true)->orderby('updated_at', 'desc')->get(); if (count($pendings) > 0) { foreach ($pendings as $key => $value) { if ($value->process_option != '') { $check = $this->call($value->process_name, ['queueid' => $value->id, '--queuefunc' => $value->process_option]); } else { $check = $this->call($value->process_name, ['queueid' => $value->id]); } } } return true; }
/** * Sends out the messages in email queue and update the database. * * @return boolean true if all messages are successfully sent out */ public function process() { $success = true; $items = Queue::find()->where(['and', ['sent_time' => null], ['<', 'attempts', $this->maxAttempts]])->orderBy(['created_at' => SORT_ASC])->limit($this->mailsPerRound)->all(); // dd($items); if (!empty($items)) { foreach ($items as $item) { /** @var \app\models\Queue $item */ if ($message = $item->toMessage()) { $attributes = ['attempts', 'last_attempt_time']; if ($this->sendMessage($message)) { // $item->sent_time = new Expression('NOW()'); // $attributes[] = 'sent_time'; $item->delete(); } else { $success = false; } $item->attempts++; $item->last_attempt_time = new Expression('NOW()'); $item->updateAttributes($attributes); } } } return $success; }
/** * 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; }
public function actionInstall() { if ($install = Queue::find()->one()) { $site = Site::findOne(['id' => $install->domain_id]); if ($this->_install($site->domain, $install->title, $install->admin, $install->password, $install->email)) { $install->delete(); $site->status = 'active'; $site->save(); } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Queue::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'book_id' => $this->book_id, 'user_id' => $this->user_id, 'reg_date' => $this->reg_date]); return $dataProvider; }
/** * Store a queue * * 1. Validate Price Parameter * * @return Response */ public function price() { if (!Input::has('price')) { return new JSend('error', (array) Input::all(), 'Tidak ada data price.'); } $user = \LucaDegasperi\OAuth2Server\Facades\Authorizer::getResourceOwnerId(); $user = json_decode($user, true)['data']; if ($user) { $userid = $user['id']; } else { \App::abort(404); } $errors = new MessageBag(); DB::beginTransaction(); //1. Validate Price Parameter $price = Input::get('price'); $price_rules = ['discount_amount' => 'required_without:discount_percentage|numeric', 'discount_percentage' => 'required_without:discount_amount|numeric', 'started_at' => 'required|date_format:"Y-m-d H:i:s"', 'ended_at' => 'required|date_format:"Y-m-d H:i:s"|after:started_at', 'category_ids' => 'required_if:item,category|array', 'tag_ids' => 'required_if:item,tag|array', 'is_labeled' => 'boolean']; $validator = Validator::make($price, $price_rules); if (!$validator->passes()) { $errors->add('Price', $validator->errors()); } else { $products = new \App\Models\Product(); $products = $products->sellable(true); if (isset($price['category_ids'])) { $products = $products->categoriesid($price['category_ids']); } elseif (isset($price['tag_ids'])) { $products = $products->tagsid($price['tag_ids']); } $products = $products->get(['id']); $parameter = $price; $queue = new \App\Models\Queue(); $queue->fill(['user_id' => $userid, 'process_name' => 'broadcast:discount', 'parameter' => json_encode($parameter), 'total_process' => count($products), 'task_per_process' => 1, 'process_number' => 0, 'total_task' => count($products), 'message' => 'Initial Commit']); if (!$queue->save()) { $errors->add('Product', $queue->getError()); } } //End of validate price if ($errors->count()) { DB::rollback(); return new JSend('error', (array) Input::all(), $errors); } DB::commit(); $final_queue = \App\Models\Queue::id($queue['id'])->first()->toArray(); return new JSend('success', (array) $final_queue); }
/** * Finds the Queue model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Queue the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Queue::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 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; }
/** * 1. check product * 2. Price Changed * 2.*. Art of discount1 : if there were discount amount, prices will be reduced by certain amount * 2.*. Art of discount2 : if there were discount amount, prices will be reduced by certain amount * 2.*. Art of discount3 : if there were discount percentage, prices will be reduced by certain percentage * * @return true * @author **/ public function broadcastdiscount($id) { $queue = new Queue(); $pending = $queue->find($id); $parameters = json_decode($pending->parameter, true); $messages = json_decode($pending->message, true); //1. Check product $products = new \App\Models\Product(); $products = $products->sellable(true); //1a. Only for certain category if (isset($parameters['category_ids'])) { $products = $products->categoriesid($parameters['category_ids']); } elseif (isset($parameters['tag_ids'])) { $products = $products->tagsid($parameters['tag_ids']); } $products = $products->get(); //2. Price Changed foreach ($products as $idx => $product) { $errors = new MessageBag(); //2a. Check price on that end period //if there were setup price right after end date, do nothing //if there were setup price after end date, but not precisely duplicated latest and expand right after //if there were no setup price right after end date, duplicate latest price with right after end date $price = \App\Models\Price::productid($product['id'])->where('started_at', '>', date('Y-m-d H:i:s', strtotime($parameters['ended_at'])))->orderby('started_at', 'desc')->first(); $promo = 0; if ($price) { if (date('Y-m-d H:i:s', strtotime($parameters['ended_at'] . ' + 1 second')) != $price['started_at']->format('Y-m-d H:i:s')) { $prev = $price->toArray(); $price = new \App\Models\Price(); $price->fill($prev); $price->started_at = date('Y-m-d H:i:s', strtotime($parameters['ended_at'] . ' + 1 second')); if (!$price->save()) { $errors->add('Price', $price->getError()); } } } else { $price = \App\Models\Price::productid($product['id'])->ondate($parameters['ended_at'])->orderby('started_at', 'desc')->first(); if ($price) { $prev = $price->toArray(); $price = new \App\Models\Price(); $price->fill($prev); $price->started_at = date('Y-m-d H:i:s', strtotime($parameters['ended_at'] . ' + 1 second')); if (!$price->save()) { $errors->add('Price', $price->getError()); } } } //2b. Check price on that start day //if there were setup price right after start date, create new one //if there were setup price exactly in time, update promo price $price = \App\Models\Price::productid($product['id'])->ondate($parameters['started_at'])->orderby('started_at', 'desc')->first(); $promo = 0; if ($price) { if (isset($parameters['discount_amount']) && isset($parameters['discount_percentage']) && $parameters['discount_percentage'] != 0) { $promo = $price['price'] - $parameters['discount_amount'] - ($price['price'] - $parameters['discount_amount']) * $parameters['discount_percentage'] / 100; } elseif (isset($parameters['discount_amount'])) { $promo = $price['price'] - $parameters['discount_amount']; } elseif (isset($parameters['discount_percentage']) && $parameters['discount_percentage'] != 0) { $promo = $price['price'] - $price['price'] * $parameters['discount_percentage'] / 100; } if ($parameters['started_at'] == $price['started_at']->format('Y-m-d H:i:s')) { $price->promo_price = "{$promo}"; } else { $prev = $price->toArray(); $price = new \App\Models\Price(); $price->fill($prev); $price->started_at = $parameters['started_at']; $price->promo_price = "{$promo}"; } if (!$price->save()) { $errors->add('Price', $price->getError()); } } //2c. Check price on that period //if there were setup price during period, update promo price $prices = \App\Models\Price::productid($product['id'])->ondate([date('Y-m-d H:i:s', strtotime($parameters['started_at'] . ' + 1 second')), $parameters['ended_at']])->orderby('started_at', 'desc')->get(); foreach ($prices as $key => $value) { $price = \App\Models\Price::id($value['id'])->first(); if ($price) { if (isset($parameters['discount_amount']) && isset($parameters['discount_percentage']) && $parameters['discount_percentage'] != 0) { $promo = $price['price'] - $parameters['discount_amount'] - ($price['price'] - $parameters['discount_amount']) * $parameters['discount_percentage'] / 100; } elseif (isset($parameters['discount_amount'])) { $promo = $price['price'] - $parameters['discount_amount']; } elseif (isset($parameters['discount_percentage']) && $parameters['discount_percentage'] != 0) { $promo = $price['price'] - $price['price'] * $parameters['discount_percentage'] / 100; } $price->promo_price = "{$promo}"; if (!$price->save()) { $errors->add('Price', $price->getError()); } } } if (!$errors->count()) { $pnumber = $pending->process_number + 1; $messages['message'][$pnumber] = 'Sukses Menyimpan Perubahan Harga ' . (isset($product['name']) ? $product['name'] : ''); $pending->fill(['process_number' => $pnumber, 'message' => json_encode($messages)]); } else { $pnumber = $pending->process_number + 1; $messages['message'][$pnumber] = 'Gagal Menyimpan Perubahan Harga ' . (isset($product['name']) ? $product['name'] : ''); $messages['errors'][$pnumber] = $errors; $pending->fill(['process_number' => $pnumber, 'message' => json_encode($messages)]); } $pending->save(); } return true; }