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(); } }
/** * Check models have proper relations with each other. */ public function testModelRelations() { /** @var Site $site */ /** @noinspection PhpUndefinedMethodInspection */ $this->assertNotNull($site = Site::firstOrFail()); $this->assertNotEmpty($site->posts); /** @var Post $post */ $post = null; foreach ($site->posts as $curPost) { /** @var Post $curPost */ $this->assertNotNull($curPost->site); if ($curPost->site_id === $site->id) { $post = $curPost; break; } } $this->assertNotNull($post); $this->assertNotNull($post->site); $this->assertEquals($site->id, $post->site_id); /** @var Author $author */ $this->assertNotNull($author = $post->author); $this->assertNotEmpty($author->posts); foreach ($author->posts as $curPost) { /** @var Post $curPost */ $this->assertNotNull($curPost->author); } $this->assertNotEmpty($post->comments); foreach ($post->comments as $curComment) { /** @var Comment $curComment */ $this->assertNotNull($curComment); $this->assertEquals($post->id, $curComment->post_id); } }
/** * Display a listing of the resource. * * @return Response */ public function uploadComments() { $title = '上传评论'; $is_nav = 'uploadComments'; $sites = Site::where('status', 1)->get(); return view('site.uploadComments', array('title' => $title, 'is_nav' => $is_nav, 'sites' => $sites)); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $siteID = $request->route('sites'); $site = \App\Models\Site::find($siteID); // normal and admin users accessing other site info if (\Auth::user()->super == "No") { if (\Auth::user()->site_id != $siteID) { if ($request->ajax()) { return response('Unauthorized', 401); } else { return redirect()->guest('noAccess'); } } } // if super user is trying to access a site belonging to another company if (\Auth::user()->super == "Yes") { if (\Auth::user()->site->company_id != $site->company_id) { if ($request->ajax()) { return response('Unauthorized', 401); } else { return redirect()->guest('noAccess'); } } } return $next($request); }
/** * Remove the specified resource from storage. * * @param int $id * * @return Response */ public function destroy($id) { $this->checkParametersEmpty(); $site = Site::findOrFail($id); $site->delete(); return $this->getCodeResponse(Response::HTTP_NO_CONTENT); }
public static function location($parameter = "") { if ($parameter == "") { return Md\Site::count(); } if ($parameter != "") { return Md\Site::where('category', $parameter)->count(); } }
public function index() { $sites = Site::where('status', 1)->get(); $str = ''; foreach ($sites as $site) { $str .= "'{$site->db_name}' => [" . "<br />" . "'driver' => 'mysql'," . "<br />" . "'host' => '" . $site->db_ip . "'," . "<br />" . "'database' => '" . $site->db_name . "'," . "<br />" . "'username' => '" . $site->db_user . "'," . "<br />" . "'password' => '" . $site->db_pass . "'," . "<br />" . "'charset' => 'utf8'," . "<br />" . "'collation'=> 'utf8_unicode_ci'," . "<br />" . "'prefix' => ''," . "<br />" . "'strict' => false" . "<br />" . "]," . "<br />" . "<br />" . "<br />"; } //echo $str; }
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(); } } }
/** * * @param boolean $active * @return Ambigous <\yii\db\ActiveRecord, multitype:, NULL>|boolean */ public function check($active = true) { $args = ['domain' => Yii::$app->getRequest()->serverName]; if ($active) { $args['status'] = 'active'; } if ($site = Site::find()->where($args)->one()) { $this->_checkAccess($site); return $site; } return false; }
/** * Seeds the table. * * @return void */ public function run() { $post = new Post(); $post->title = 'JSON API paints my bikeshed!'; $post->body = 'If you\'ve ever argued with your team about the way your JSON responses should be ' . 'formatted, JSON API is your anti-bikeshedding weapon.'; /** @var Site $site */ $site = Site::firstOrFail(); /** @var Author $author */ $author = Author::firstOrFail(); $post->site_id = $site->id; $post->author_id = $author->id; $post->save(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Site::find()->where(['user_id' => Yii::$app->user->id]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]); $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, 'user_id' => $this->user_id]); $query->andFilterWhere(['like', 'domain', $this->domain]); return $dataProvider; }
public function current() { if (app()->runningInConsole()) { return null; } $id = $this->id(); $cacheKey = 'site_current_' . $id; $site = Cache::get($cacheKey); if (empty($site)) { $site = \App\Models\Site::where('id', $id)->first(); } $expiresAt = Carbon::now()->addMinutes(10); Cache::put($cacheKey, $site, $expiresAt); return $site; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (env('APP_ENV') === 'testing') { return $next($request); } $authenticated = false; if (!isset($_SERVER['HTTP_X_SITE_NAME'])) { return response()->json(array('error' => 'This resource requires a site name.'), 403); } $key = $_SERVER['HTTP_X_SITE_NAME']; if ($key) { $key = Site::where('url', '=', $key)->first(); if ($key) { session(['site_id' => $key->id]); $authenticated = true; } } if (!$authenticated) { return response()->json(array('error' => 'Invalid Site'), 403); } return $next($request); }
/** * Seeds the table. * * @return void */ public function run() { $site = new Site(); $site->name = 'JSON API Samples'; $site->save(); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { Site::where('server_id', $id)->delete(); $code = 200; $msg = json_encode(array('msg' => $code)); return $msg; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(UpdateToolRequest $request, $id) { // $tool = \App\Models\Tool::find($id); $tool->fill($request->all()); $type = \Request::get("type"); // if company tool has been transferred $iPreviousSiteID = $tool->user->site_id; if ($tool->user->site_id != $request->get("site_id")) { $iNewSiteID = \App\Models\Site::find($request->get("site_id"))->users()->where("admin", "=", "Yes")->first()->site_id; $tool->user_id = \App\Models\Site::find($request->get("site_id"))->users()->where("admin", "=", "Yes")->first()->id; // send notification $notification = new \App\Models\Notification(); $notification->message = '<a href="' . url("tools/" . $tool->id) . '">' . $tool->name . '</a>' . " has been transferred to this job site."; $notification->user_id = $tool->user_id; $notification->save(); //send email Mail::send('emails.transfers', ['tool' => $tool], function ($m) { $m->from('*****@*****.**', 'Tag and Track'); $m->to('*****@*****.**', 'Leanne')->subject('Company Tool has been transferred'); }); // transfers table $transfer = new \App\Models\Transfer(); $transfer->previous_site_id = $iPreviousSiteID; $transfer->current_site_id = $iNewSiteID; $transfer->tool_id = $tool->id; $transfer->save(); } // reset notifications flags, when retag date changes if ($tool->retag_date != $request->get("retag_date")) { $tool->five_notice = 0; $tool->three_notice = 0; $tool->one_notice = 0; } $tool->save(); if ($request->has('tech_name')) { $name = $request->get('tech_name'); $company = $request->get('tech_company'); $phone = $request->get('contact_number'); $technician = \App\Models\Technician::where("tech_name", '=', $name)->where("tech_company", '=', $company)->where("contact_number", '=', $phone)->first(); // if technician doesn't exist if ($technician == false) { $technician = Technician::create($request->all()); } $tool->technician_id = $technician->id; $tool->save(); } if ($type == "Company") { return redirect('tools?type=Company')->with('message-update', 'Update successful.'); } else { return redirect('tools?type=Personal')->with('message-update', 'Update successful.'); } }
/** * Finds the Site model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param string $site * @return Site the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($site) { if (($model = Site::find()->where(['domain' => $site, 'user_id' => Yii::$app->user->id])->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getJson(Site $site, $id) { return $site->find($id); }
/** * @return \yii\db\ActiveQuery */ public function getSite() { return $this->hasOne(Site::className(), ['id' => 'site_id']); }
public function show($path) { $site = Site::findPath($path, true, true); Site::$site = $site; return view($site->view(), array('site' => $site)); }
Route::get('countusers', function () { $user = \Auth::user(); if ($user->admin == 'Yes') { $users = \App\Models\User::whereIn("id", function ($query) { $query->select('id')->from("users")->where('site_id', \Auth::user()->site_id); })->count(); } else { $users = \App\Models\User::whereIn("id", function ($query) { $query->select('users.id')->from("users")->join("sites", "site_id", "=", "sites.id")->where('company_id', \Auth::user()->site->company_id); })->count(); } return $users; }); Route::get('countsites', function () { $sites = \App\Models\Site::whereIn("id", function ($query) { $query->select('sites.id')->from("sites")->where('company_id', \Auth::user()->site->company_id); })->count(); return $sites; }); // ===== email routes ===== // ===== login and logout routes ===== Route::get('login', 'LoginController@showLoginForm'); Route::post('login', 'LoginController@processLogin'); Route::get('logout', 'LoginController@logout'); // ===== users routes ===== Route::resource('users', 'UsersController'); // ===== tools routes ===== Route::resource('tools', 'ToolsController'); // ===== sites routes ===== Route::resource('sites', 'SitesController'); // ===== notifications routes =====
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(UpdateJobSiteRequest $request, $id) { // $site = \App\Models\Site::find($id); $site->fill($request->all()); $site->save(); return redirect('sites/' . $site->id)->with('update-success', 'Job Site has been updated.'); }
public static function site_list() { return Md\Site::orderBy('name', 'asc')->groupBy('site.name', 'site.site_id')->get(); }