Пример #1
0
    /**
     * Construct
     * @access public
     */
    public function __construct() {
        
        // db
        $options = array(
            Zend_Db::ALLOW_SERIALIZATION => false
        );

        $params = array(
            'host'           => 'localhost',
            'username'       => 'root',
            'password'       => '',
            'dbname'         => 'twitter_tracker',
            'options'        => $options
        );

        try {
            $this->db = Zend_Db::factory('Pdo_Mysql', $params);
            $this->db->getConnection();
        } catch (Zend_Db_Adapter_Exception $e) {
            // perhaps a failed login credential, or perhaps the RDBMS is not running
            echo 'failed login credentials\n';
            print_r($e);
        } catch (Zend_Exception $e) {
            // perhaps factory() failed to load the specified Adapter class
            echo 'failed to load specified adapter class\n';
            print_r($e);
        }
        
        $this->table_name = 'tweets';
        
        // twitter
        $this->ts  = new Zend_Service_Twitter_Search('json');
        
    }
Пример #2
0
 /**
  * Database injector
  *
  * @param mixed $database MongoDB instance, Database instance, string identifier.
  *
  * @return object $this
  */
 public function setDatabase($database)
 {
     if (!$database instanceof MongoDB) {
         $database = $this->connection->getConnection()->{$database};
     }
     $this->database = $database;
     return $this;
 }
Пример #3
0
 /**
  * Executes a prepared statement.
  *
  * If the prepared statement included parameter markers, you must either:
  * call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
  * bound variables pass their value as input and receive the output value,
  * if any, of their associated parameter markers or pass an array of input-only
  * parameter values.
  *
  * @param array $params An array of values with as many elements as there are
  *                      bound parameters in the SQL statement being executed.
  *
  * @return boolean Returns TRUE on success or FALSE on failure.
  */
 public function execute($params = null)
 {
     try {
         return $this->statement->execute($params);
     } catch (PDOException $e) {
         //It's empty.
     } catch (Doctrine_Adapter_Exception $e) {
         $this->statement->getConnection()->rethrowException($e, $this);
         return false;
     }
 }
 /**
  * The execute method
  *
  * @param InputInterface  $input  The Input class
  * @param OutputInterface $output The output class
  *
  * @access protected
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $start_date = time();
     $this->em = $this->getContainer()->get('doctrine')->getManager('default');
     $root_dir = $this->getContainer()->getParameter("kernel.root_dir") . "/config/gatling/data";
     PiFileManager::mkdirr($root_dir, 0777);
     $path = $root_dir . "/connexion_sfynx.csv";
     file_put_contents($path, 'username,password' . "\n", LOCK_EX);
     //
     $firstId = (int) $input->getOption('firstId');
     $lastId = (int) $input->getOption('lastId');
     $output->writeln('First id user : '******'last id user : '******'fr_FR', :user, :user, :user, :user, 1, '73rwkq08i3wo0ow840c0g48k800o0ok', " . "'xREF5HHqHbZmlmoO3+s5BXtVtYa3TIf8Wv+IVXJsQwx+0FG1WnqxjJ46toQ1u/+v1lfKOwo90FqEbqiPDzDo+g==', '2014-11-13 00:00:00', " . "0, 0, NULL, NULL, NULL, 'a:1:{i:0;s:9:\"ROLE_USER\";}', 'a:4:{i:0;s:4:\"VIEW\";i:1;s:4:\"EDIT\";i:2;s:6:\"CREATE\";i:3;s:6:\"DELETE\";}', 0, NULL, :user, :user, '2014-11-12 17:55:21' " . ");";
     $this->em->getConnection()->beginTransaction();
     $stmtuser = $this->em->getConnection()->prepare($sqluser);
     try {
         $psw = "user";
         $start_date_user = time();
         for ($j = $firstId; $j <= $lastId; $j++) {
             $user_value = 'user' . $j;
             $params = array('id' => $j, 'user' => $user_value, 'user' => $user_value, 'user' => $user_value, 'user' => $user_value, 'user' => $user_value, 'user' => $user_value);
             $stmtuser->execute($params);
             //
             file_put_contents($path, "{$user_value},{$psw}\n", FILE_APPEND);
         }
         $end_date_user = time();
         $duration_user = $end_date_user - $start_date_user;
         $output->writeln(" - fin de chargement de données des users en " . $duration_user . "s");
         $this->em->flush();
         // Try and commit the transaction
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $output->writeln($e->getMessage());
         // Rollback the failed transaction attempt
         $this->em->getConnection()->rollback();
         $this->em->close();
     }
     $end_date = time();
     $duration = $end_date - $start_date;
     $output->writeln(" - fin de chargement de donnée en " . $duration . "s");
 }
Пример #5
0
 /**
  * Get all of the queries that would be run for a migration.
  *
  * @param  object  $migration
  * @param  string  $method
  * @return array
  */
 protected function getQueries($migration, $method)
 {
     $connection = $migration->getConnection();
     // Now that we have the connections we can resolve it and pretend to run the
     // queries against the database returning the array of raw SQL statements
     // that would get fired against the database system for this migration.
     $db = $this->resolveConnection($connection);
     return $db->pretend(function () use($migration, $method) {
         $migration->{$method}();
     });
 }
Пример #6
0
 /**
  * Compiles the statements for UPDATE
  *
  * @param   object  $db  The database instance
  * @return  \Gleez\Database\Query  The current object
  */
 public function compileUpdate($db)
 {
     $query = 'UPDATE ';
     if ($this->into !== null) {
         $query .= $this->_identifier . $db->table_prefix() . $this->into . $this->_identifier . ' ';
     }
     if (!empty($this->set)) {
         $query .= 'SET ';
         $query_sub = array();
         foreach ($this->set as $column => $value) {
             // MVA support
             if (is_array($value)) {
                 $query_sub[] = $db->getConnection()->quoteIdentifier($column) . ' = (' . implode(', ', $db->getConnection()->quoteArr($value)) . ')';
             } else {
                 if ((is_string($value) and array_key_exists($value, $this->_parameters)) === FALSE) {
                     $query_sub[] = $db->getConnection()->quoteIdentifier($column) . ' = ' . $db->getConnection()->quote($value);
                 } else {
                     $query_sub[] = $db->getConnection()->quoteIdentifier($column) . ' = ' . $value;
                 }
             }
         }
         $query .= implode(', ', $query_sub) . ' ';
     }
     $query .= $this->compileWhere($db);
     // pass the
     $this->_query = $query;
     return $this;
 }
Пример #7
0
 /**
  * @param object $migration
  * @param string $method
  * @return array
  */
 protected function getQueries($migration, $method)
 {
     $connection = $migration->getConnection();
     $db = $this->resolveConnection($connection);
     return $db->pretend(function () use($migration, $method) {
         $migration->{$method}();
     });
 }
Пример #8
0
 /**
  * Run a migration inside a transaction if the database supports it.
  *
  * @param  object  $migration
  * @param  string  $method
  * @return void
  */
 protected function runMigration($migration, $method)
 {
     $name = $migration->getConnection();
     $connection = $this->resolveConnection($name);
     $callback = function () use($migration, $method) {
         $migration->{$method}();
     };
     $grammar = $this->getSchemaGrammar($connection);
     $grammar->supportsSchemaTransactions() ? $connection->transaction($callback) : $callback();
 }
Пример #9
0
    /**
     * Construct
     * @access public
     */
    public function __construct() {
        
        // detect server environment
        $root = $_SERVER['DOCUMENT_ROOT'];
        
        $is_local = (strpos($root, 'XAMPP')) ? true : false;
        
        // db
        $options = array(
            Zend_Db::ALLOW_SERIALIZATION => false
        );
        
        $params = array(
            'host'           => 'localhost',
            'username'       => 'sfsb_admin',
            'password'       => 'superdata',
            'dbname'         => 'twitter_tracker',
            'options'        => $options
        );
        
        if($is_local) {
            $params = array(
                'host'           => 'localhost',
                'username'       => 'root',
                'password'       => '',
                'dbname'         => 'twitter_tracker',
                'options'        => $options
            );
        }

        try {
            $this->db = Zend_Db::factory('Pdo_Mysql', $params);
            $this->db->getConnection();
        } catch (Zend_Db_Adapter_Exception $e) {
            // perhaps a failed login credential, or perhaps the RDBMS is not running
            if($is_local) {
//                echo 'failed login credentials\n';
                print_r($e);
            }
        } catch (Zend_Exception $e) {
            // perhaps factory() failed to load the specified Adapter class
            if($is_local) {
//                echo 'failed to load specified adapter class\n';
                print_r($e);
            }
        }
        
        $this->table_name = 'tweets';
        
        // twitter
        // DEPRECATED
//        $this->ts   = new Zend_Service_Twitter_Search('json');
        
        // codebird - for search
        // NOTE: I will try with alex to make this work first, if it's not possible to upgrade php to 5.3 then I will write my own library referencing this:
        // https://github.com/thatericsmith/simple-php-twitter-getter/blob/master/TwitterGetter.php
        \Codebird\Codebird::setConsumerKey('Mr3tmdYJtDUBHFCIi0tPQw', 'yPFzdcuzEj0fc8jwuzrE4LdJhmNGnaiqlfv8aOVwGRU'); // static, see 'Using multiple Codebird instances'
        $cb = \Codebird\Codebird::getInstance();
        $cb->setToken('850078843-rKjQFWOzZzPSUCdEyQIJOHvQo6Yna1ohGP8El83K', 'wE6HRo7mPguFT7atpJGHURUccuW5kXYKvLa1WevS0Y');
        $this->cb = $cb;
        
        $file = "bearer.txt";
        if(file_exists($file)) {
//            echo "using " . $file;
//            echo '<br />';
            $bearer_token = file_get_contents($file);
//            echo "using b token: " . $bearer_token;
//            echo '<br />';
            \Codebird\Codebird::setBearerToken($bearer_token);
        } else {
//            echo "getting new bearer token";
//            echo '<br />';
            $reply = $this->cb->oauth2_token();
            $bearer_token = $reply->access_token;
//            echo "setting new bearer toekn to file: " . $bearer_token;
//            echo '<br />';
            file_put_contents($file, $bearer_token);
        }
        
        $this->bearer_token = $bearer_token;
            
    }