/** * Execute the console command. * * @return mixed */ public function handle() { $series = $this->argument('series'); $data = json_decode($this->filesystem->get(base_path('resources/assets/json/' . $series . '_full.json'))); $series = $this->series->create((array) $data); $this->db->table('cards')->whereNull('series_id')->update(['series_id' => $series->id]); }
public function delete() { $data = $this->request->get('data'); $id_string = $data['id_string']; $this->db->table("widgets")->where("id_string", $id_string)->delete(); $this->db->table("sidebar_widget")->where("id_string", $id_string)->delete(); }
/** * Return information about a scope * * @param string $scope * @param string $grantType * @param string $clientId * @return ScopeEntity */ public function get($scope, $grantType = null, $clientId = null) { $result = $this->db->table('oauth_scopes')->where('id', $scope)->get(); if (count($result) === 0) { return; } return (new ScopeEntity($this->server))->hydrate(['id' => $result->id, 'description' => $result->description]); }
/** * Add participants to a conversation * * @param $partecipants * @param bool $multiPartecipants * @return \Illuminate\Database\Eloquent\Model|static */ public function add($partecipants, $multiPartecipants = false) { if (!$multiPartecipants) { $insert = $this->convJoined->create($partecipants); } else { $insert = $this->db->table('conversation_joined')->insert($partecipants); } return $insert; }
/** * {@inheritdoc} */ public function validate() { $check = $this->database->table('captcha')->where('imagehash', '=', $this->request->get('imagehash'))->where('imagestring', '=', $this->request->get('imagestring')); if ($check->count() != 1) { $this->database->table('captcha')->where('imagehash', '=', $this->request->get('imagehash'))->delete(); return false; } return true; }
/** * Deletes an option from the database. * * @param string $key option name * * @return bool TRUE on success, FALSE on failure * * @throws NonExistentOptionException */ public function delete($key) { $result = $this->db->table($this->optionsTable)->where(['option_key' => $key])->delete(); if (0 === $result && !$this->has($key)) { throw new NonExistentOptionException('The option key: "' . $key . '" doesn\'t exists'); } return FALSE !== $result; }
public function isUserInConversation($conv_id, $user_id) { $res = $this->db->table($this->tablePrefix . 'conv_users')->select('conv_id', 'user_id')->where('user_id', $user_id)->where('conv_id', $conv_id)->first(); if (is_null($res)) { return false; } return true; }
/** * @param DatabaseManager $databaseManager */ function __construct(DatabaseManager $databaseManager) { $db_versions = $databaseManager->table('versions')->get(); $versions = []; foreach ($db_versions as $ver) { $versions[$ver->version] = $ver->version; } $this->versions = $versions; }
/** * @param string $imagehash */ public function captcha($imagehash) { $baseQuery = $this->database->table('captcha')->where('imagehash', '=', $imagehash)->where('used', '=', false); // Something is wrong here... if ($baseQuery->count() != 1) { exit; } $imagestring = $baseQuery->pluck('imagestring'); // Mark as used $baseQuery->update(['used' => true]); // $imagestring = 'Debug'; if ($this->getGdVersion() >= 2) { $im = imagecreatetruecolor($this->img_width, $this->img_height); } else { $im = imagecreate($this->img_width, $this->img_height); } // Couldn't create the image :( if ($im === false) { throw new \RuntimeException("Couldn't create an image using GD"); } // Fill the background with white $bg_color = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $bg_color); // Now draw random circles, squares or lines $to_draw = mt_rand(0, 2); if ($to_draw == 1) { $this->drawCircles($im); } elseif ($to_draw == 2) { $this->drawSquares($im); } else { $this->drawLines($im); } // Dots are always added $this->drawDots($im); // Now write the image string to the image $this->drawString($im, $imagestring); // Draw a nice border around the image $border_color = imagecolorallocate($im, 0, 0, 0); imagerectangle($im, 0, 0, $this->img_width - 1, $this->img_height - 1, $border_color); // And now output the image header('Content-type: image/png'); imagepng($im); imagedestroy($im); }
/** * @param string $identifier * * @return \Illuminate\Database\Query\Builder */ public function queryUsersByIdentifier($identifier) { $first = $this->getEntities()->first(); $query = $this->database->table($first->table)->selectRaw($this->database->raw("'{$first->type}' AS type, id, `{$first->identifier}` AS identifier"))->where($first->identifier, '=', $identifier); foreach ($this->getEntities()->slice(1) as $entity) { $subQuery = $this->database->table($entity->table)->selectRaw($this->database->raw("'{$entity->type}' AS type, id, `{$entity->identifier}` AS identifier"))->where($entity->identifier, '=', $identifier); $query = $query->union($subQuery); } return $query; }
public function getShowPost($permalink = "") { if (!$permalink) { exit('Not found.'); } $post = $this->db->table('cms.cms_posts', ['permalink', $permalink])->first(); if (!$post) { exit('404 not found'); } return $this->theme->baseDashboard("Front::view.single", ['post' => $post]); }
/** * Set cache * * @return array */ protected function setCache() { // Check if cache has expired if ($this->cache->expired() === false) { return; } // Instantiate values $values = array(); // Get values from database foreach ($this->database->table($this->config['table'])->get() as $setting) { $values[$setting->key] = json_decode($setting->value, true); } // Cache values $this->cache->set($values); }
/** * Handle a login request to the application. * * @param Request|\Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function postLogin(Request $request) { $this->validate($request, ['login' => 'required', 'password' => 'required']); $login = $request->input('login'); $field = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'username'; $request->merge([$field => $login]); $credentials = $request->only($field, 'password'); try { if ($this->requiresPasswordReset($credentials)) { $this->resetPassword($credentials['password']); } if (Auth::attempt($credentials, $request->has('remember'))) { if (!Auth::user()->enabled) { Auth::logout(); return redirect('/auth/login')->withErrors("Your account has been disabled. Please contact us at <a href='mailto:support@aidstream.org'>support@aidstream.org</a> "); } $user = Auth::user(); Session::put('role_id', $user->role_id); Session::put('org_id', $user->org_id); Session::put('admin_id', $user->id); $settings = Settings::where('organization_id', $user->org_id)->first(); $settings_check = isset($settings); $version = $settings_check ? $settings->version : config('app.default_version'); Session::put('current_version', $version); $versions_db = $this->database->table('versions')->get(); $versions = []; foreach ($versions_db as $ver) { $versions[] = $ver->version; } $versionKey = array_search($version, $versions); $next_version = end($versions) == $version ? null : $versions[$versionKey + 1]; Session::put('next_version', $next_version); $version = 'V' . str_replace('.', '', $version); Session::put('version', $version); $redirectPath = $user->role_id == 1 || $user->role_id == 2 ? config('app.admin_dashboard') : config('app.super_admin_dashboard'); $intendedUrl = Session::get('url.intended'); !(($user->role_id == 3 || $user->role_id == 4) && strpos($intendedUrl, '/admin') === false) ?: ($intendedUrl = url('/')); !($intendedUrl == url('/')) ?: Session::set('url.intended', $redirectPath); return redirect()->intended($redirectPath); } return redirect($this->loginPath())->withInput($request->only($field, 'remember'))->withErrors([$field => $this->getFailedLoginMessage()]); } catch (\Exception $exception) { return redirect()->back()->withErrors($exception->getMessage()); } }
/** * Check whether a specific Role has the specified permission * * @param Role $role The role to check * @param string $permission The permission to check * @param string|null $content If the permission is related to some content (eg forum) this string specifies the * type of text * @param int|null $contentID If $content is set this specifies the ID of the content to check * * @return PermissionChecker::NEVER|NO|YES */ public function getPermissionForRole(Role $role, $permission, $content = null, $contentID = null) { // Permissions associated with user/groups are saved without content // (all permissions are associated with groups anyways) if ($content == 'user' || $content == 'usergroup') { $content = null; $contentID = null; } if ($this->hasCache($role, $permission, $content, $contentID)) { return $this->getCache($role, $permission, $content, $contentID); } // Get the value if we have one otherwise the devault value $permissionValues = $this->db->table('permissions')->where('permission_name', '=', $permission)->where('content_name', '=', $content)->leftJoin('permission_role', function ($join) use($role, $content, $contentID) { $join->on('permission_id', '=', 'id')->where('role_id', '=', $role->id); if ($content != null && $contentID != null) { $join->where('content_id', '=', $contentID); } })->first(['value', 'default_value']); // If the permission doesn't exist return "Never" to break all loops but don't cache it as it may be added later if ($permissionValues == null) { return static::NEVER; } // We have a content value so we can save that as permission if ($permissionValues->value !== null) { $this->putCache($role, $permission, $content, $contentID, $permissionValues->value); return $permissionValues->value; } // We have a content permission without a specific value // Now we need to check whether this role has a content permission (#122) // Unfortunately Laravel doesn't have a subwhere for joins so we can't add it to the query above if ($content != null && $contentID != null) { $contentValues = $this->db->table('permissions')->where('permission_name', '=', $permission)->where('content_name', '=', $content)->leftJoin('permission_role', function ($join) use($role, $content, $contentID) { $join->on('permission_id', '=', 'id')->where('role_id', '=', $role->id)->where('content_id', '=', 0); })->first(['value']); if ($contentValues != null && $contentValues->value !== null) { $this->putCache($role, $permission, $content, $contentID, $contentValues->value); return $contentValues->value; } } $this->putCache($role, $permission, $content, $contentID, $permissionValues->default_value); return $permissionValues->default_value; }
/** * Display a listing of the resource. * * @return Response */ public function index(DatabaseManager $db, Request $request) { $users = User::select('u_id', 'u_name', 'e-mail', 'location', 'skype', 'int_phone', 'desks.id as desk', 'departmants.job', 'departmants.dep', 'departmants.users as dep_users', 'rights.users as rights')->leftJoin('desks', 'users_id', '=', 'u_id')->leftJoin('rights', 'user_id', '=', 'u_id')->join('departmants', 'departmants.id', '=', 'departmant_id')->where('departmant_id', '!=', 21)->get()->keyBy('u_id')->toArray(); $host = getenv('COMPUTERNAME'); if (!in_array($host, ['SOFWKS0188', 'SOFWKS0159', 'SOFWKS0140'])) { $host = explode('.', gethostbyaddr($request->server->get('REMOTE_ADDR'))); $host = $host[0]; } $res = $db->table('computers')->select('user_id')->where('name', '=', $host)->first(); if ($res) { $users[$res->user_id]['current'] = true; $users[$res->user_id]['edit'] = $this->checkUser($users[$res->user_id]); } // Apply data restrictions if (empty($res) || !$users[$res->user_id]['edit']) { $users = $this->filterRestrictedData($users); } $users = array_merge($users, $this->getSpecialUsers()); return response()->json($users); }
/** * Empty trash * * @param int $day * @return array $ids */ public function emptyTrash($day = 60) { //Convert day to carbon object $date = Carbon::now()->subDays($day); //Prepare the query to get only trash $query = $this->model->onlyTrashed(); //Archived since $query->where('deleted_at', '<', $date->toDateTimeString()); //Execute the query $trash = $query->get(); //By default, no ids $ids = []; //For each results, add ids foreach ($trash as $result) { $ids[] = $result->id; } //If we have archive to delete if (!empty($ids)) { $this->db->table($this->model->getTable())->whereIn('id', $ids)->delete(); } return $ids; }
/** * continue version upgrade * @param $version * @return \Illuminate\Http\RedirectResponse */ public function show($version, DatabaseManager $databaseManager) { if (!$this->version) { return redirect()->back(); } $result = $this->upgrade(); if ($result) { Session::put('current_version', $version); $versions_db = $databaseManager->table('versions')->get(); $versions = []; foreach ($versions_db as $ver) { $versions[] = $ver->version; } $versionKey = array_search($version, $versions); $next_version = end($versions) == $version ? null : $versions[$versionKey + 1]; Session::put('next_version', $next_version); $response = ['type' => 'success', 'code' => ['upgraded', ['version' => $version]]]; } else { $response = ['type' => 'danger', 'code' => ['upgrade_failed']]; } return redirect('/settings')->withResponse($response); }
/** * Associate a scope with a session * * @param SessionEntity $session * @param ScopeEntity $scope * @return void */ public function associateScope(SessionEntity $session, ScopeEntity $scope) { $this->db->table('oauth_session_scopes')->insert(['session_id' => $session->getId(), 'scope_id' => $scope->getId(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); }
/** * Delete the refresh token * * @param RefreshTokenEntity $token * @return void */ public function delete(RefreshTokenEntity $token) { $this->db->table('oauth_refresh_tokens')->where('id', $token->getId())->delete(); }
/** * Delete setting from the database * * @param $field * @return mixed */ public function deleteSetting($field) { return $this->database->table(self::table)->where('id', $field)->delete(); }
/** * Display settings * * @param FormBuilder $formBuilder * @param DatabaseManager $databaseManager * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function index(FormBuilder $formBuilder, DatabaseManager $databaseManager) { $currentUser = auth()->user(); if ($currentUser->isNotAdmin()) { return redirect()->back()->withResponse(['type' => 'warning', 'code' => ['message', ['message' => 'You do not have the correct privileges to view this page.']]]); } $db_versions = $databaseManager->table('versions')->get(); $versions = []; foreach ($db_versions as $ver) { $versions[] = $ver->version; } $model = []; if (isset($this->settings->default_field_groups)) { $version = $this->settings->version; // $model['version_form'] = [['version' => $version]]; $model['publishing_type'] = [['publishing' => $this->settings->publishing_type]]; $model['registry_info'] = $this->settings->registry_info; $model['default_field_values'] = $this->settings->default_field_values; $model['default_field_groups'] = $this->settings->default_field_groups; } else { $version = config('app.default_version'); $data = '{"reporting_organization_info":[{"reporting_organization_identifier":"","reporting_organization_type":"10","organization_name":"","reporting_organization_language":"es"}],"publishing_type":[{"publishing":"unsegmented"}],"registry_info":[{"publisher_id":"","api_id":"","publish_files: ":"no"}],"default_field_values":[{"default_hierarchy":"1"}],"default_field_groups":[{"title":"Title","description":"Description","activity_status":"Activity Status","activity_date":"Activity Date","participating_org":"Participating Org","recipient_county":"Recipient Country","sector":"Sector","budget":"Budget","transaction":"Transaction"}]}'; $model = json_decode($data, true); } if (isset($this->organization)) { $model['reporting_organization_info'] = $this->organization->reporting_org; } $url = isset($this->settings) ? route('update-settings') : route('settings.store'); $method = isset($this->settings) ? 'PUT' : 'POST'; $formOptions = ['method' => $method, 'url' => $url]; if (!empty($model)) { $formOptions['model'] = $model; } $form = $formBuilder->create('App\\Core\\V201\\Forms\\SettingsForm', $formOptions); return view('settings', compact('form', 'version', 'versions')); }
/** * Delete an access token * * @param AuthCodeEntity $token * @return void */ public function delete(AuthCodeEntity $token) { $this->db->table('oauth_auth_codes')->where('oauth_auth_codes.id', $token->getId())->delete(); }
/** * Get the object for the current table * * @return mixed */ private function getTableObject() { return $this->database->table($this->table); }
/** * @param null $time * @return mixed */ public function clear($time = null) { return $this->db->table($this->model->getTable())->where('updated_at', '<', date($this->db->getQueryGrammar()->getDateFormat(), strtotime('-' . $time . ' minutes')))->delete(); }
/** * Set the database table to be used in the query. * * @param string $table * @return $this */ public function table($table) { $this->query = $this->db->table($table); return $this; }
/** * Delete an access token * * @param AccessTokenEntity $token * @return void */ public function delete(AccessTokenEntity $token) { $this->db->table('oauth_access_tokens')->where('oauth_access_tokens.id', $token->getId())->delete(); }
/** * @param string $group * @param string $version */ public function removeMigrationLog($group, $version) { $this->db->table($this->table)->where('group', $group)->where('version', $version)->delete(); }
/** * Update an existing user. * * @param \Stidges\LaravelDbNormalizer\Entity $user * @return bool */ public function update(Entity $user) { $data = array_only($user->toArray(), $this->fillable); return (bool) $this->db->table($this->table)->where('id', $user->id)->update($data); }
/** * delete all options from db. * * @return void */ public function clear() { $this->db->table($this->getTable())->truncate(); }
/** * Remove all settings * * @return bool */ public function flush() { $this->cache->flush(); return $this->database->table($this->config['db_table'])->delete(); }