Exemplo n.º 1
0
 private function getDatabase()
 {
     $conn = new ConnectionFactory($this->app);
     $manager = new DatabaseManager($this->app, $conn);
     $manager->setDefaultConnection('sqlite');
     return array($conn, $manager);
 }
 /**
  * updates Activity Document Link
  * @param array                $documentLink
  * @param ActivityDocumentLink $activityDocumentLink
  * @return bool
  */
 public function update(array $documentLink, ActivityDocumentLink $activityDocumentLink)
 {
     try {
         $this->database->beginTransaction();
         $documentLinkExists = $activityDocumentLink->exists;
         $activityId = $activityDocumentLink->activity_id;
         $documentManager = app(DocumentManager::class);
         if ($documentLinkExists) {
             $url = $activityDocumentLink->document_link['url'];
             $document = $documentManager->getDocument(session('org_id'), $url);
             $activities = (array) $document->activities;
             unset($activities[$activityId]);
             $document->activities = $activities;
             $documentManager->update($document);
         }
         $url = $documentLink[0]['url'];
         $document = $documentManager->getDocument(session('org_id'), $url);
         $activities = (array) $document->activities;
         $identifier = $activityDocumentLink->activity->identifier['activity_identifier'];
         $activities[$activityId] = $identifier;
         $document->activities = $activities;
         $documentManager->update($document);
         $this->DocumentLinkRepo->update($documentLink, $activityDocumentLink);
         $this->database->commit();
         $this->logger->info(sprintf('Activity Document Link %s!', $documentLinkExists ? 'updated' : 'saved'), ['for' => $documentLink]);
         $this->dbLogger->activity(sprintf("activity.document_link_%s", $documentLinkExists ? 'updated' : 'saved'), ['activity_id' => $activityDocumentLink->activity_id, 'document_link_id' => $activityDocumentLink->id, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
         return true;
     } catch (\Exception $exception) {
         $this->database->rollback();
         $this->logger->error($exception, ['documentLink' => $documentLink]);
     }
     return false;
 }
 public function testCreateSecondaryIndex()
 {
     $cluster = new \CouchbaseCluster('127.0.0.1');
     $clusterManager = $cluster->manager('Administrator', 'Administrator');
     $clusterManager->createBucket($this->bucket, ['bucketType' => 'couchbase', 'saslPassword' => '', 'flushEnabled' => true]);
     sleep(5);
     /** @var \Ytake\LaravelCouchbase\Database\CouchbaseConnection $connection */
     $connection = $this->databaseManager->connection('couchbase');
     $bucket = $connection->openBucket($this->bucket);
     $bucket->manager()->createN1qlPrimaryIndex();
     sleep(4);
     $output = new \Symfony\Component\Console\Output\BufferedOutput();
     $this->command->run(new \Symfony\Component\Console\Input\ArrayInput(['bucket' => $this->bucket, 'name' => 'testing_gsi', 'fields' => ['params1', 'params2']]), $output);
     $fetch = $output->fetch();
     $this->assertSame("created SECONDARY INDEX [testing_gsi] fields [params1,params2], for [index_testing] bucket.", trim($fetch));
     /** @var \Ytake\LaravelCouchbase\Database\CouchbaseConnection $connection */
     $connection = $this->databaseManager->connection('couchbase');
     $bucket = $connection->openBucket($this->bucket);
     $indexes = $bucket->manager()->listN1qlIndexes();
     foreach ($indexes as $index) {
         if (!$index->isPrimary && $index->keyspace === 'keyspace') {
             $this->assertSame("testing_gsi", $index->name);
             $this->assertInstanceOf('CouchbaseN1qlIndex', $index);
         }
     }
     $bucket->manager()->dropN1qlPrimaryIndex();
     $bucket->manager()->dropN1qlIndex('testing_gsi');
     $clusterManager->removeBucket($this->bucket);
 }
 public function __construct(UserRepositoryInterface $users, DatabaseManager $db, Encrypter $encrypter)
 {
     $this->users = $users;
     $this->encrypter = $encrypter;
     $this->table = Config::get('authentify::auth_tokens.table');
     parent::__construct($db->connection());
 }
Exemplo n.º 5
0
 /**
  * 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]);
 }
Exemplo n.º 6
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->init();
     $this->app->singleton('Larapress\\Services\\Helpers', function () {
         return new Helpers($this->app['config'], $this->app['translator'], $this->app['view'], $this->app['Larapress\\Interfaces\\MockablyInterface'], $this->app->make('log')->getMonolog(), $this->app['request'], $this->app['session.store'], $this->db->connection($this->defaultDbConnection), $this->app['redirect'], $this->app['Illuminate\\Support\\Facades\\Response'], $this->app['app'], $this->app['Carbon\\Carbon']);
     });
 }
 /**
  * upload activity form csv
  * @param $activityCsv
  * @param $organization
  * @param $defaultFieldValues
  * @return bool
  */
 public function save($activityCsv, $organization, $defaultFieldValues)
 {
     try {
         $excel = $this->version->getExcel();
         $activitiesRows = $excel->load($activityCsv)->get();
         $activityDetails = [];
         foreach ($activitiesRows as $activityRow) {
             $activityDetails[] = $this->uploadActivityRepo->formatFromExcelRow($activityRow, $organization->id);
         }
         $identifiers = $this->uploadActivityRepo->getIdentifiers($organization->id);
         $this->database->beginTransaction();
         $data = [];
         foreach ($activityDetails as $activityDetail) {
             $activityIdentifier = $activityDetail['identifier']['activity_identifier'];
             isset($identifiers[$activityIdentifier]) ? $data[$identifiers[$activityIdentifier]] = $activityDetail : $this->uploadActivityRepo->upload($activityDetail, $organization, $defaultFieldValues);
             $this->database->commit();
         }
         if (count($data) > 0) {
             return view('Activity.confirmUpdate')->withData($data);
         }
         $this->logger->info("Activities Uploaded for organization with id:" . $organization->id);
         $this->dbLogger->activity("activity.activity_uploaded", ['organization_id' => $organization->id]);
         return true;
     } catch (Exception $exception) {
         $this->database->rollback();
         $this->logger->error($exception, ['activity' => $activityDetails]);
     }
     return false;
 }
 /**
  * Builder constructor.
  * @param DatabaseManager $databaseManager
  * @param AppConfig $appConfig
  */
 public function __construct(DatabaseManager $databaseManager, AppConfig $appConfig)
 {
     $this->manager = $databaseManager->connection()->getDoctrineSchemaManager();
     $this->appConfig = $appConfig;
     $this->tablePrefix = $databaseManager->connection() - getTablePrefix();
     $this->registerUserTypes();
 }
 /**
  * @param MethodInvocation $invocation
  *
  * @return object
  * @throws \Exception
  */
 public function invoke(MethodInvocation $invocation)
 {
     /** @var \Illuminate\Database\ConnectionInterface $database */
     $annotation = $invocation->getMethod()->getAnnotation($this->annotation);
     $connection = $annotation->value;
     $database = self::$databaseManager->connection($connection);
     $database->beginTransaction();
     try {
         $result = $invocation->proceed();
         $database->commit();
     } catch (\Exception $exception) {
         // for default Exception
         if ($exception instanceof QueryException) {
             $database->rollBack();
             throw $exception;
         }
         if ($exception instanceof $annotation->expect) {
             $database->rollBack();
             throw $exception;
         }
         $database->rollBack();
         throw $exception;
     }
     return $result;
 }
Exemplo n.º 10
0
 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();
 }
Exemplo n.º 11
0
 /**
  * Execute the console command
  */
 public function fire()
 {
     /** @var \Illuminate\Database\Connection|CouchbaseConnection $connection */
     $connection = $this->databaseManager->connection($this->option('database'));
     if ($connection instanceof CouchbaseConnection) {
         $bucket = $connection->openBucket($this->argument('bucket'));
         $primary = self::PRIMARY_KEY;
         try {
             $bucket->manager()->createN1qlPrimaryIndex($primary, $this->option('ignore'), $this->option('defer'));
             $this->info("created PRIMARY INDEX [{$primary}] for [{$this->argument('bucket')}] bucket.");
         } catch (\Exception $e) {
             $this->error($e->getMessage());
         }
         foreach ($this->secondaryIndexes as $name => $fields) {
             try {
                 $bucket->manager()->createN1qlIndex($name, $fields, '', $this->option('ignore'), $this->option('defer'));
                 $field = implode(",", $fields);
                 $this->info("created SECONDARY INDEX [{$name}] fields [{$field}], for [{$this->argument('bucket')}] bucket.");
             } catch (\Exception $e) {
                 $this->error($e->getMessage());
             }
         }
     }
     return;
 }
 /**
  * @inheritdoc
  */
 public function process(EloquentModel $model, Config $config)
 {
     $schemaManager = $this->databaseManager->connection()->getDoctrineSchemaManager();
     $prefix = $this->databaseManager->connection()->getTablePrefix();
     if (!$schemaManager->tablesExist($prefix . $model->getTableName())) {
         throw new GeneratorException(sprintf('Table %s does not exist', $prefix . $model->getTableName()));
     }
 }
Exemplo n.º 13
0
 public function __construct(Factory $event_snapshot_factory, Builder $stream_builder, DatabaseManager $manager, $table, $stream_table)
 {
     $this->event_snapshot_factory = $event_snapshot_factory;
     $this->stream_builder = $stream_builder;
     $this->connection = $manager->connection();
     $this->table = $table;
     $this->stream_table = $stream_table;
 }
 public function __construct(DatabaseManager $DB, AuthenticationManagementInterface $AuthenticationManager, Translator $Lang)
 {
     // $this->DB = $DB;
     // $this->DB->connection()->enableQueryLog();
     $this->Database = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Period AS p')->join('ACCT_Fiscal_Year AS f', 'f.id', '=', 'p.fiscal_year_id')->where('p.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->whereNull('p.deleted_at');
     $this->visibleColumns = array('p.id AS acct_pm_id', 'p.month as acct_pm_month', 'p.start_date as acct_pm_start_date', 'p.end_date as acct_pm_end_date', 'p.is_closed as acct_pm_is_closed', 'f.year as acct_pm_year');
     $this->orderBy = array(array('acct_pm_year', 'desc'), array('acct_pm_month', 'asc'));
 }
 public function __construct(DatabaseManager $DB, AuthenticationManagementInterface $AuthenticationManager)
 {
     // $this->DB = $DB;
     // $this->DB->connection()->enableQueryLog();
     $this->Database = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Fiscal_Year AS f')->where('f.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->whereNull('f.deleted_at');
     $this->visibleColumns = array('f.id AS acct_cfy_id', 'f.year AS acct_cfy_year', 'f.start_date AS acct_cfy_start_date', 'f.end_date AS acct_cfy_end_date');
     $this->orderBy = array(array('acct_cfy_id', 'asc'));
 }
Exemplo n.º 16
0
 /**
  * @param $year
  * @param $month
  * @return \Illuminate\View\View
  */
 public function archive($year, $month)
 {
     $data = $this->getOverviewData();
     $posts = $this->post->forPublic()->where($this->db->raw('MONTHNAME(publish_date)'), '=', $month)->where($this->db->raw('YEAR(publish_date)'), '=', $year)->orderBy('publish_date', 'DESC')->paginate($this->config->items_per_page);
     $data['posts'] = $this->dateFormat($posts);
     $data['headings'] = "All posts from <strong>" . $month . " " . $year . "</strong>";
     return view('blogify.index', $data);
 }
Exemplo n.º 17
0
 /**
  * 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]);
 }
 public function __construct(DatabaseManager $DB, AuthenticationManagementInterface $AuthenticationManager, AccountManagementInterface $AccountManager, Translator $Lang, Carbon $Carbon)
 {
     $this->DB = $DB;
     $this->AccountManager = $AccountManager;
     $this->AuthenticationManager = $AuthenticationManager;
     $this->Carbon = $Carbon;
     $this->Database = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Journal_Entry AS je')->join('ACCT_Account AS c', 'je.account_id', '=', 'c.id')->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')->leftJoin('PURCH_Document_Type AS dt', 'dt.id', '=', 'jv.document_type_id')->leftJoin('PURCH_Supplier AS ps', 'ps.id', '=', 'jv.supplier_id')->leftJoin('SALE_Client AS cl', 'cl.id', '=', 'jv.client_id')->leftJoin('HR_Employee AS e', 'e.id', '=', 'jv.employee_id')->join('ACCT_Voucher_Type AS vt', 'vt.id', '=', 'jv.voucher_type_id')->where('jv.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->where('c.is_group', '=', 0)->where('jv.status', '=', 'B')->whereNull('je.deleted_at')->whereNull('jv.deleted_at')->select(array('jv.date', 'jv.number', 'jv.remark', 'jv.manual_reference', 'vt.name AS voucher_type_name', 'jv.document_date', 'jv.document_number', 'jv.document_amount', 'dt.name AS document_type_name', $DB->raw('CONCAT(e.names, \' \', e.surnames) AS employee_name'), 'e.tax_id as employee_tax_id', 'e.single_identity_document_number as employee_single_identity_document_number', 'ps.name as supplier_name', 'ps.registration_number AS supplier_registration_number', 'ps.tax_id as supplier_tax_id', 'ps.single_identity_document_number as supplier_single_identity_document_number', 'cl.name as client_name', 'cl.registration_number AS client_registration_number', 'cl.tax_id as client_tax_id', 'cl.single_identity_document_number as client_single_identity_document_number', 'c.key AS account_key', 'c.name AS account_name', 'je.debit', 'je.credit'));
     $this->orderBy = array(array('jv.document_date', 'asc'));
 }
Exemplo n.º 19
0
 /**
  * fire.
  *
  * @method fire
  */
 public function fire()
 {
     $connection = $this->databaseManager->connection();
     $connection->setFetchMode(PDO::FETCH_ASSOC);
     $query = $this->option('command');
     $rows = $connection->select($query);
     $headers = array_keys(Arr::get($rows, 0, []));
     $this->table($headers, $rows);
 }
Exemplo n.º 20
0
 /**
  * {@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;
 }
Exemplo n.º 21
0
 /**
  * @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;
 }
Exemplo n.º 22
0
 public function run()
 {
     if ($this->truncate) {
         $this->db->connection()->table($this->getTableName())->truncate();
     }
     foreach ($this->seeds as $seed) {
         $this->getModelInstance()->create($seed);
     }
 }
Exemplo n.º 23
0
 /**
  * Return a description for each table.
  *
  * @return \Generator
  */
 public function tables()
 {
     $schema = $this->db->connection()->getDoctrineConnection()->getSchemaManager();
     $tables = $schema->listTableNames();
     foreach ($tables as $table) {
         $columns = $this->describer->describe($table);
         (yield compact('table', 'columns'));
     }
 }
 public function __construct(DatabaseManager $DB, AuthenticationManagementInterface $AuthenticationManager, Translator $Lang)
 {
     // $this->DB = $DB;
     // $this->DB->connection()->enableQueryLog();
     $this->Database = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Cost_Center AS c')->leftJoin('ACCT_Cost_Center AS cp', 'cp.id', '=', 'c.parent_cc_id')->where('c.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->whereNull('c.deleted_at');
     $this->visibleColumns = array('c.id AS acct_ccm_id', 'c.key as acct_ccm_key', 'c.name as acct_ccm_name', 'c.is_group as acct_ccm_is_group', 'cp.id as acct_ccm_parent_cc_id', 'cp.key as acct_ccm_parent_key', 'cp.name as acct_ccm_parent_cc', $DB->raw('CASE c.is_group WHEN 1 THEN 0 ELSE 1 END AS acct_ccm_is_leaf'));
     $this->orderBy = array(array('acct_ccm_key', 'asc'));
     $this->treeGrid = true;
     $this->parentColumn = 'cp.id';
     $this->leafColumn = 'acct_ccm_is_leaf';
 }
 /**
  * Execute the console command
  */
 public function fire()
 {
     /** @var \Illuminate\Database\Connection|CouchbaseConnection $connection */
     $connection = $this->databaseManager->connection($this->option('database'));
     if ($connection instanceof CouchbaseConnection) {
         $bucket = $connection->openBucket($this->argument('bucket'));
         $bucket->manager()->dropN1qlPrimaryIndex($this->option('name'), $this->option('ignore'));
         $this->info("dropped PRIMARY INDEX [{$this->option('name')}] for [{$this->argument('bucket')}] bucket.");
     }
     return;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $connection = $this->argument('connection');
     $name = $this->database->connection($connection)->getDatabaseName();
     try {
         $this->database->connection($connection)->reconnect();
     } catch (\Exception $e) {
         return $this->error($e->getMessage());
     }
     $this->info(sprintf('Connected with database "%s" through connection "%s"', $name, $connection));
 }
 public function __construct(DatabaseManager $DB, AuthenticationManagementInterface $AuthenticationManager, Translator $Lang)
 {
     // $this->DB = $DB;
     // $this->DB->connection()->enableQueryLog();
     $this->Database = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Account AS a')->leftJoin('ACCT_Account AS ap', 'ap.id', '=', 'a.parent_account_id')->join('ACCT_Account_Type AS at', 'at.id', '=', 'a.account_type_id')->where('a.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->whereNull('a.deleted_at');
     $this->visibleColumns = array('a.id AS acct_am_id', 'a.key as acct_am_key', 'a.name as acct_am_name', 'a.balance_type as acct_am_balance_type', 'a.is_group as acct_am_is_group', 'a.account_type_id as acct_am_account_type_id', 'at.name as acct_am_account_type', 'ap.id as acct_am_parent_account_id', 'ap.key as acct_am_parent_key', 'ap.name as acct_am_parent_account', $DB->raw('CASE a.balance_type WHEN "D" THEN "' . $Lang->get('decima-accounting::account-management.D') . '" ELSE "' . $Lang->get('decima-accounting::account-management.A') . '" END AS acct_am_balance_type_name'), $DB->raw('CASE a.is_group WHEN 1 THEN 0 ELSE 1 END AS acct_am_is_leaf'));
     $this->orderBy = array(array('acct_am_key', 'asc'));
     $this->treeGrid = true;
     $this->parentColumn = 'ap.id';
     $this->leafColumn = 'acct_am_is_leaf';
 }
Exemplo n.º 28
0
 /**
  * Check if given participants are
  * in a conversation
  *
  * @param $participants
  * @return mixed
  */
 public function inConversation($participants)
 {
     list($num_user_in_conversation, $valuesEscaped) = $this->getEscapedValues($participants);
     // prepare question marks for the query
     $questionmarks = str_repeat("?,", $num_user_in_conversation - 1) . "?";
     $query = $this->db->select($this->db->raw('select cu.conversation_id, cu.deleted_at
                     from conversation_joined cu
                     group by cu.conversation_id, cu.deleted_at
                     having SUM(cu.participant_id in ( ' . $questionmarks . ' )) = ? and
                            SUM(cu.participant_id not in ( ' . $questionmarks . ' )) = 0
                            '), $valuesEscaped);
     return $query;
 }
Exemplo n.º 29
0
 /**
  * updates username
  * @param                 $userId
  * @param UsernameRequest $usernameRequest
  * @param DatabaseManager $database
  * @return mixed
  */
 public function updateUsername($userId, UsernameRequest $usernameRequest, DatabaseManager $database)
 {
     $input = $usernameRequest->all();
     $user = $this->user->findOrFail($userId);
     $organization = $this->organization->findOrFail($this->orgId);
     $database->beginTransaction();
     $organization->user_identifier = $input['organization_user_identifier'];
     $user->username = $input['username'];
     $user->save();
     $organization->save();
     $database->commit();
     $response = $user->save() && $organization->save() ? ['type' => 'success', 'code' => ['updated', ['name' => 'Username']]] : ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Username']]];
     return redirect('user/profile')->withResponse($response);
 }
Exemplo n.º 30
0
 /**
  * @param $tables
  */
 private function truncateTables($tables)
 {
     $this->truncatedCount = 0;
     foreach ($tables as $table) {
         if (!in_array($table, $this->exclude)) {
             $this->truncatedCount++;
             $this->db->statement('SET FOREIGN_KEY_CHECKS=0;');
             $this->db->statement("TRUNCATE TABLE {$table}");
             $this->db->statement('SET FOREIGN_KEY_CHECKS=1;');
             $this->info("Table {$table} successfully truncated.");
         }
     }
     $this->info("Total table(s) truncated: {$this->truncatedCount}");
 }