Esempio n. 1
1
 public function indexDirectory($dir)
 {
     if (!file_exists($dir)) {
         throw new Doctrine_Search_Indexer_Exception('Unknown directory ' . $dir);
     }
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY);
     $files = array();
     foreach ($it as $file) {
         $name = $file->getPathName();
         if (strpos($name, '.svn') === false) {
             $files[] = $name;
         }
     }
     $q = new Doctrine_Query();
     $q->delete()->from('Doctrine_File f')->where('f.url LIKE ?', array($dir . '%'))->execute();
     // clear the index
     $q = new Doctrine_Query();
     $q->delete()->from('Doctrine_File_Index i')->where('i.file_id = ?')->execute();
     $conn = Doctrine_Manager::connection();
     $coll = new Doctrine_Collection('Doctrine_File');
     foreach ($files as $file) {
         $coll[]->url = $file;
     }
     $coll->save();
 }
 private function saveRelatedAttributeSelections($embed_token)
 {
     // Get the relevant form
     $forms = $this->embeddedForms;
     if (isset($forms[$embed_token])) {
         $stock_forms = $forms[$embed_token]->getEmbeddedForms();
         // Get the stock values from request
         $request_data = $this->getValue($embed_token);
         foreach ($request_data as $name => $form) {
             // Save form object
             if (!isset($stock_forms[$name])) {
                 continue;
             }
             $stock_object = $stock_forms[$name]->getObject();
             $stock_object->save();
             $query = new Doctrine_Query();
             //        $stock_object->unlink('rtShopVariations', array(), true);
             $query->delete('rtShopStockToVariation s2v')->where('s2v.stock_id = ?', $stock_object->getId())->execute();
             $values = array();
             foreach ($this->getAttributes() as $attribute) {
                 $tmp_val = $form['rt_shop_variations_list_' . $attribute->getId()];
                 $values[$tmp_val[0]] = $tmp_val[0];
             }
             $stock_object->link('rtShopVariations', array_values($values), true);
         }
     }
 }
 public function testDeleteWithLimitAndOffset()
 {
     $q = new Doctrine_Query();
     $q->parseDqlQuery('DELETE FROM Entity LIMIT 10 OFFSET 20');
     $this->assertEqual($q->getSqlQuery(), 'DELETE FROM entity LIMIT 10 OFFSET 20');
     $q = new Doctrine_Query();
     $q->delete()->from('Entity')->limit(10)->offset(20);
     $this->assertEqual($q->getSqlQuery(), 'DELETE FROM entity LIMIT 10 OFFSET 20');
 }
 public function saveVariationSelections()
 {
     return;
     $request = sfContext::getInstance()->getRequest();
     $full_data = $request->getParameter('rt_shop_product');
     foreach ($full_data['currentStocks'] as $stock) {
         if ($stock['id'] == $this->getObject()->getId()) {
             $attributes = $this->getAttributes();
             $values = array();
             $query = new Doctrine_Query();
             $query->delete('rtShopStockToVariation s2v')->where('s2v.stock_id = ?', $this->object->getId())->execute();
             foreach ($attributes as $a) {
                 $tmp_val = $stock['rt_shop_variations_list_' . $a->getId()];
                 $values[] = $tmp_val[0];
             }
             $this->object->link('rtShopVariations', array_values($values), true);
         }
     }
 }
Esempio n. 5
0
 /**
  * removeAccess
  * defines unified access removal strategy for users and groups
  *
  * Removes an access rule defined for this user.
  *
  * @param Koch_User|Koch_Group $record
  * @param string               $resource   name of the resource
  * @param string               $permission name of the permission
  *
  * @return boolean True on success, false otherwise.
  */
 public function removeAccess(Doctrine_Record $record, $resource = null, $permission = null)
 {
     // ensure $record is either object of type User or Group
     if ($record instanceof Koch_User) {
         $accessClass = 'Koch_Acl_UserAccess';
         $linkField = 'user_id';
     } elseif ($record instanceof Koch_Group) {
         $accessClass = 'Koch_Acl_GroupAccess';
         $linkField = 'group_id';
     } else {
         throw new Koch_Exception('Unknown object given to ACM.');
     }
     if ($permission === null) {
         $permission = $this->getOption('global_permission');
     }
     if ($resource === null) {
         $resource = $this->getOption('global_resource');
     }
     $rows = Doctrine_Query::delete()->from($accessClass . ' a')->where('a.' . $linkField . ' = ? AND a.resource_name = ? AND a.permission_name = ?')->execute(array($record->id, $resource, $permission));
     return (bool) $rows;
 }
Esempio n. 6
0
 public function executeUpdate($request)
 {
     $time_values = $request->getParameter('time', array());
     $user = UserTable::getInstance()->find($this->getUser()->getAttribute('uid'));
     $this->time_values = $time_values;
     for ($i = 1; $i <= 7; $i++) {
         if (!array_key_exists($i, $time_values)) {
             continue;
         }
         $projects = $time_values[$i];
         $booking_timestamp = $request->getParameter('weekstart') + ($i - 1) * 24 * 60 * 60;
         $booking_date = date("Y-m-d", $booking_timestamp);
         if ($booking_timestamp < time()) {
             foreach ($projects as $pid => $project) {
                 $query = new Doctrine_Query();
                 $query->delete('TimeLogItem ti')->where('ti.user_id=? AND ti.project_id=? AND ti.itemdate=?', array($this->getUser()->getAttribute('uid'), $pid, $booking_date))->execute();
                 for ($time_index = 0; $time_index < count($project['time']); $time_index++) {
                     $time_value = $project['time'][$time_index];
                     $time_type = $project['type'][$time_index];
                     $time_comment = $project['comment'][$time_index];
                     if ($time_value != "" && $time_value != 0) {
                         $type_query = new Doctrine_Query();
                         $type = $type_query->from('TimeItemType tit')->where('tit.name=?', array($time_type))->fetchOne();
                         $current_value = new TimeLogItem();
                         $current_value->value = $time_value;
                         $current_value->itemdate = $booking_date;
                         $current_value->user_id = $this->getUser()->getAttribute('uid');
                         $current_value->project_id = $pid;
                         $current_value->type_id = $type->id;
                         $current_value->note = $time_comment;
                         $current_value->save();
                     }
                 }
             }
             TimeLogItemTable::getInstance()->updateMissedBookings($booking_timestamp, $user);
         }
     }
     $this->getUser()->setFlash('saved.success', 1);
     $this->redirect('timesheet/index?year=' . $request->getParameter('year', date('Y')) . '&week=' . $request->getParameter('week', date('W')));
 }
Esempio n. 7
0
 public function unlinkInDb($alias, $ids = array())
 {
     $q = new Doctrine_Query();
     $rel = $this->getTable()->getRelation($alias);
     if ($rel instanceof Doctrine_Relation_Association) {
         $q->delete()->from($rel->getAssociationTable()->getComponentName())->where($rel->getLocal() . ' = ?', array_values($this->identifier()));
         if (count($ids) > 0) {
             $q->whereIn($rel->getForeign(), $ids);
         }
         $q->execute();
     } else {
         if ($rel instanceof Doctrine_Relation_ForeignKey) {
             $q->update($rel->getTable()->getComponentName())->set($rel->getForeign(), '?', array(null))->addWhere($rel->getForeign() . ' = ?', array_values($this->identifier()));
             if (count($ids) > 0) {
                 $q->whereIn($rel->getTable()->getIdentifier(), $ids);
             }
             $q->execute();
         }
     }
     return $this;
 }
Esempio n. 8
0
 /**
  * unlink
  * removes links from this record to given records
  * if no ids are given, it removes all links
  *
  * @param string $alias     related component alias
  * @param array $ids        the identifiers of the related records
  * @return Doctrine_Record  this object
  */
 public function unlink($alias, $ids = array())
 {
     $ids = (array) $ids;
     $q = new Doctrine_Query();
     $rel = $this->getTable()->getRelation($alias);
     if ($rel instanceof Doctrine_Relation_Association) {
         $q->delete()->from($rel->getAssociationTable()->getComponentName())->where($rel->getLocal() . ' = ?', array_values($this->identifier()));
         if (count($ids) > 0) {
             $q->whereIn($rel->getForeign(), $ids);
         }
         $q->execute();
     } else {
         if ($rel instanceof Doctrine_Relation_ForeignKey) {
             $q->update($rel->getTable()->getComponentName())->set($rel->getForeign(), '?', array(null))->addWhere($rel->getForeign() . ' = ?', array_values($this->identifier()));
             if (count($ids) > 0) {
                 $q->whereIn($rel->getTable()->getIdentifier(), $ids);
             }
             $q->execute();
         }
     }
     if (isset($this->_references[$alias])) {
         foreach ($this->_references[$alias] as $k => $record) {
             if (in_array(current($record->identifier()), $ids)) {
                 $this->_references[$alias]->remove($k);
             }
         }
         $this->_references[$alias]->takeSnapshot();
     }
     return $this;
 }
Esempio n. 9
0
 /**
  * Deletes Comments
  *
  * @param unknown_type $cid
  * @param unknown_type $xid
  * @param unknown_type $aid
  * @return Number of Rows Deleted
  */
 public static function deleteComment($cid, $xid, $aid)
 {
     $q = new Doctrine_Query();
     return $q->delete('RingsideComment')->from('RingsideComment c')->where("cid={$cid} AND xid='{$xid}' AND aid={$aid}")->execute();
 }
Esempio n. 10
0
 /**
  * Deletes a Trust Authority and a Users Network
  *
  * @param unknown_type $nid
  */
 public static function deleteNetwork($nid)
 {
     $q = new Doctrine_Query();
     $q->delete('RingsideRsTrustAuthority')->from('RingsideRsTrustAuthority a')->where("trust_key='{$nid}'")->execute();
     $q = new Doctrine_Query();
     return $q->delete('RingsideUsersNetwork')->from('RingsideUsersNetwork n')->where("network_id='{$nid}'")->execute();
 }
Esempio n. 11
0
 public static function deletePlan($planId)
 {
     $q = new Doctrine_Query();
     return $q->delete('RingsideSocialPayPlan')->from('RingsideSocialPayPlan p')->where("id = {$planId}")->execute();
 }
 /**
  * loadDataFromArray 
  * 
  * @param mixed $data 
  * @access public
  * @return void
  */
 public function loadDataFromArray($data)
 {
     $pendingRelations = array();
     if ($data === null) {
         // no data
         return;
     }
     // only for pake_echo_action
     require_once sfConfig::get('sf_symfony_lib_dir') . '/vendor/pake/pakeFunction.php';
     foreach ($data as $class => $entries) {
         pake_echo_action('Filling', sprintf('class "%s"', $class) . "\t");
         // fetch a table object
         $table = sfDoctrine::getTable($class, $this->connectionName);
         $colNames = array_keys($table->getColumns());
         $tableName = $table->getTableName();
         // relation fields
         $relations = $table->getRelations();
         //echo "Class $class: ".implode(', ', array_keys($relations))."\n";
         if ($this->deleteCurrentData) {
             $q = new Doctrine_Query();
             $q->delete()->from($class);
             $q->execute();
         }
         // iterate through entries for this class
         // might have been empty just for force a table to be emptied on import
         if (is_array($entries)) {
             foreach ($entries as $key => $columnAssignments) {
                 // create a new entry in the database
                 $obj = $table->create();
                 $now = date("Y-m-d H:i:s", time());
                 if ($obj->getTable()->hasColumn('created_at')) {
                     $obj->set('created_at', $now);
                 }
                 if (!is_array($columnAssignments)) {
                     throw new Exception('You must give a name for each fixture data entry');
                 }
                 foreach ($columnAssignments as $name => $value) {
                     $isRelation = isset($relations[$name]);
                     // foreign key?
                     if ($isRelation) {
                         $rel = $relations[$name];
                         // $relatedTable = $rel->getTable()->getTableName();
                         $localKey = $rel->getLocal();
                         $foreignKey = $rel->getForeign();
                         $pendingRelations[] = array($obj, $localKey, $foreignKey, $value);
                     } else {
                         // first check that the column exists
                         if (!in_array($name, $colNames)) {
                             $error = 'Column "%s" does not exist for class "%s"';
                             $error = sprintf($error, $name, $class);
                             throw new sfException($error);
                         }
                         $obj->rawSet($name, $value);
                     }
                 }
                 $obj->save();
                 // For progress meter
                 echo '.';
                 // save the id for future reference
                 $pk = $obj->obtainIdentifier();
                 if (isset($this->object_references[$key])) {
                     throw new sfException(sprintf('The key "%s" is not unique', $key));
                 }
                 $this->object_references[$key] = $pk;
             }
         }
         echo "\n";
     }
     // now we take care of the pending relations
     foreach ($pendingRelations as $pending) {
         list($obj, $localKey, $foreignKey, $key) = $pending;
         if (!isset($this->object_references[$key])) {
             $error = 'No object with key "%s" is defined in your data file';
             $error = sprintf($error, $key);
             throw new sfException($error);
         }
         $foreignId = $this->object_references[$key][$foreignKey];
         $obj->rawSet($localKey, $foreignId);
         $obj->save();
     }
 }
Esempio n. 13
0
 /**
  * Deletes an Album
  *
  * @param unknown_type $aid
  * @return unknown
  */
 public static function delete($aid)
 {
     $q = new Doctrine_Query();
     return $q->delete('RingsideAlbum')->from('RingsideAlbum a')->where("aid={$aid}")->execute();
 }
Esempio n. 14
0
 /**
  * Deletes an App
  *
  * @param unknown_type $aid
  * @return unknown
  */
 public static function deleteApp($id)
 {
     $q = new Doctrine_Query();
     return $q->delete('RingsideApp')->from('RingsideApp a')->where("id = {$id}")->execute();
 }