/**
  * sets a value in the preferences
  * @param string $user user
  * @param string $app app
  * @param string $key key
  * @param string $value value
  * @param string $preCondition only set value if the key had a specific value before
  * @return bool true if value was set, otherwise false
  *
  * Adds a value to the preferences. If the key did not exist before, it
  * will be added automagically.
  */
 public function setValue($user, $app, $key, $value, $preCondition = null)
 {
     // Check if the key does exist
     $query = 'SELECT `configvalue` FROM `*PREFIX*preferences`' . ' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?';
     $oldValue = $this->conn->fetchColumn($query, array($user, $app, $key));
     $exists = $oldValue !== false;
     if ($oldValue === strval($value)) {
         // no changes
         return true;
     }
     $affectedRows = 0;
     if (!$exists && $preCondition === null) {
         $data = array('userid' => $user, 'appid' => $app, 'configkey' => $key, 'configvalue' => $value);
         $affectedRows = $this->conn->insert('*PREFIX*preferences', $data);
     } elseif ($exists) {
         $data = array($value, $user, $app, $key);
         $sql = "UPDATE `*PREFIX*preferences` SET `configvalue` = ?" . " WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?";
         if ($preCondition !== null) {
             if (\OC_Config::getValue('dbtype', 'sqlite') === 'oci') {
                 //oracle hack: need to explicitly cast CLOB to CHAR for comparison
                 $sql .= " AND to_char(`configvalue`) = ?";
             } else {
                 $sql .= " AND `configvalue` = ?";
             }
             $data[] = $preCondition;
         }
         $affectedRows = $this->conn->executeUpdate($sql, $data);
     }
     // only add to the cache if we already loaded data for the user
     if ($affectedRows > 0 && isset($this->cache[$user])) {
         if (!isset($this->cache[$user][$app])) {
             $this->cache[$user][$app] = array();
         }
         $this->cache[$user][$app][$key] = $value;
     }
     return $affectedRows > 0 ? true : false;
 }
Exemple #2
0
 protected function copyTable(Connection $fromDB, Connection $toDB, $table, InputInterface $input, OutputInterface $output)
 {
     /** @var $progress \Symfony\Component\Console\Helper\ProgressHelper */
     $progress = $this->getHelperSet()->get('progress');
     $query = 'SELECT COUNT(*) FROM ' . $table;
     $count = $fromDB->fetchColumn($query);
     $query = 'SELECT * FROM ' . $table;
     $statement = $fromDB->executeQuery($query);
     $progress->start($output, $count);
     $progress->setRedrawFrequency($count > 100 ? 5 : 1);
     while ($row = $statement->fetch()) {
         $progress->advance();
         if ($input->getArgument('type') === 'oci') {
             $data = $row;
         } else {
             $data = array();
             foreach ($row as $columnName => $value) {
                 $data[$toDB->quoteIdentifier($columnName)] = $value;
             }
         }
         $toDB->insert($table, $data);
     }
     $progress->finish();
 }