Exemplo n.º 1
1
 /**
  * Creates a new logging instance.
  *
  * @param Doctrine_Event $event  Event.
  * @param int            $opType I/U/D for Insert/Update/Delete.
  *
  * @return void
  */
 private function _createOperationLog(Doctrine_Event $event, $opType = 'I')
 {
     $data = $event->getInvoker();
     $tableName = $this->getTableNameFromEvent($event);
     $idColumn = $this->getIdColumnFromEvent($event);
     $log = array();
     $log['object_type'] = $tableName;
     $log['object_id'] = $data[$idColumn];
     $log['op'] = $opType;
     if ($opType == 'U') {
         $oldValues = $data->getLastModified(true);
         $diff = array();
         foreach ($oldValues as $column => $oldValue) {
             if (empty($oldValue) && isset($data[$column]) && !empty($data[$column])) {
                 $diff[$column] = 'I: ' . $data[$column];
             } elseif (!empty($oldValue) && isset($data[$column]) && !empty($data[$column])) {
                 $diff[$column] = 'U: ' . $data[$column];
             } elseif (!empty($oldValue) && empty($data[$column])) {
                 $diff[$column] = 'D: ' . $oldValue;
             }
         }
         $log['diff'] = serialize($diff);
     } else {
         // Convert object to array (otherwise we serialize the record object)
         $log['diff'] = serialize($data->toArray());
     }
     DBUtil::insertObject($log, 'objectdata_log');
 }
Exemplo n.º 2
0
 public function preStmtExecute(Doctrine_Event $event)
 {
     // Check if the administrator has enabled the query logging feature
     if (Settings::findbyParam('debug_queries')) {
         $breadcrumps = array();
         $query = $event->getQuery();
         $params = $event->getParams();
         $callers = array_reverse(debug_backtrace(), true);
         $callers = array_slice($callers, 4, count($callers) - 10);
         foreach ($callers as $caller) {
             $class = !empty($caller['class']) ? $caller['class'] : null;
             $breadcrumps[] = $class . "->" . $caller['function'];
         }
         $strBreadcrump = "System: " . implode(" / ", $breadcrumps);
         //the below makes some naive assumptions about the queries being logged
         while (sizeof($params) > 0) {
             $param = array_shift($params);
             if (!is_numeric($param)) {
                 $param = sprintf("'%s'", $param);
             }
             $query = substr_replace($query, $param, strpos($query, '?'), 1);
         }
         Shineisp_Commons_Utilities::log($query, "queries.log");
         Shineisp_Commons_Utilities::log($strBreadcrump, "debug.log", Zend_Log::DEBUG);
         // Increase query counter
         $queryCount = Shineisp_Registry::isRegistered('querycount') ? Shineisp_Registry::get('querycount') : 0;
         $queryCount = $queryCount + 1;
         Shineisp_Registry::set('querycount', $queryCount);
     }
 }
Exemplo n.º 3
0
 /**
  * @param Doctrine_Event $event
  */
 public function preUpdate(Doctrine_Event $event)
 {
     $record = $event->getInvoker();
     $modified = $record->getModified();
     $original = $record->getModified(true);
     foreach ($this->Slices as &$slice) {
         if (array_key_exists('title', $modified)) {
             if ($slice->title == $original['title'] || $slice->title == null) {
                 $slice->title = $modified['title'];
             }
         }
         if (array_key_exists('slug', $modified)) {
             if ($slice->slug == $original['slug'] || $slice->slug == null) {
                 $slice->slug = $modified['slug'];
             }
         }
         if (array_key_exists('description', $modified)) {
             if ($slice->caption == $original['description'] || $slice->caption == null) {
                 $slice->caption = $modified['description'];
             }
         }
         if (array_key_exists('published', $modified) && $modified['published'] == false && $original['published'] == true) {
             $slice->published = false;
         }
         if (array_key_exists('published', $modified) && $modified['published'] == true && $original['published'] == false && RokGallery_Config::getOption(RokGallery_Config::OPTION_SLICE_AUTOPUBLISH_ON_FILE_PUBLISH, false)) {
             $slice->published = true;
         }
     }
     if (array_key_exists('manipulations', $modified)) {
         $this->processImages();
     }
 }
 public function preDqlDelete(Doctrine_Event $event)
 {
     $params = $event->getParams();
     $tmpQuery = clone $event->getQuery();
     $subQuery = $tmpQuery->select($params['alias'] . '.' . $params['component']['table']->getIdentifier())->getDql();
     if (!in_array($params['alias'], $tmpQuery->getDqlPart('from'))) {
         return false;
     }
     $targets = $this->detectCascadingTargets($params['component']['table']);
     foreach ($targets as $target) {
         $table = Doctrine::getTable($target['table']);
         $relation = $table->getRelation($target['aliasFrom']);
         $localField = $relation->getLocalFieldName();
         $q = $table->createQuery();
         $q = $q->where($q->getRootAlias() . '.' . $localField . ' IN (' . $subQuery . ')');
         switch (strtolower($target['delete'])) {
             case 'cascade':
                 $q->delete()->execute();
                 break;
             case 'set null':
                 $q->update()->set($localField, '?', array(null))->execute();
                 break;
             default:
                 // do nothing
         }
     }
 }
Exemplo n.º 5
0
 /**
  * preUpdate
  *
  * @param object $Doctrine_Event 
  * @return void
  */
 public function preUpdate(Doctrine_Event $event)
 {
     if (!$this->_options['updated']['disabled']) {
         $updatedName = $this->_options['updated']['name'];
         $event->getInvoker()->{$updatedName} = $this->getTimestamp('updated');
     }
 }
Exemplo n.º 6
0
 /**
  * Throws an exception if the record is modified while it is 
  * locked. 
  * 
  * @param Doctrine_Event $event 
  * @return void
  */
 public function preSave(Doctrine_Event $event)
 {
     $modelName = Doctrine_Inflector::tableize(get_class($event->getInvoker()));
     $modifiedFields = $event->getInvoker()->getModified();
     $locked = $event->getInvoker()->isLocked;
     $lockModified = array_key_exists('isLocked', $modifiedFields);
     $numModified = count($modifiedFields);
     /**
      * Record fields haven't been modified, nothing to do here. 
      */
     if (!$event->getInvoker()->isModified()) {
         return;
     }
     /**
      * The record is not locked, and the lock isn't being changed, nothing to do here. 
      */
     if (!$locked && !$lockModified) {
         return;
     }
     /**
      * Only the lock is being modified so there's nothing to
      * do here. 
      */
     if ($lockModified && $numModified == 1) {
         return;
     }
     /**
      * The record is locked, throw an exception. 
      */
     if ($locked) {
         throw new Behavior_Lockable_Exception('The record must be unlocked before it can be modified.');
     }
 }
 /**
  * Pre-save logic.
  *
  * Use preSave instead of preUpdate since the latter depends on the record's
  * state, which isn't necessarily dirty.
  *
  * @see Doctrine_Record_Listener
  */
 public function preSave(Doctrine_Event $event)
 {
     // loop through relations
     if ($relations = $this->form->getOption('dynamic_relations')) {
         foreach ($relations as $field => $config) {
             // collect form objects for comparison
             $search = array();
             foreach ($this->form->getEmbeddedForm($field)->getEmbeddedForms() as $embed) {
                 $search[] = $embed->getObject();
             }
             $collection = $event->getInvoker()->get($config['relation']->getAlias());
             foreach ($collection as $i => $object) {
                 if (false === ($pos = array_search($object, $search, true))) {
                     // if a related object exists in the record but isn't represented
                     // in the form, the reference has been removed
                     $collection->remove($i);
                     // if the foreign column is a notnull columns, delete the object
                     $column = $config['relation']->getTable()->getColumnDefinition($config['relation']->getForeignColumnName());
                     if ($object->exists() && isset($column['notnull']) && $column['notnull']) {
                         $object->delete();
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Pre update event hook for inserting new version record
  * This will only insert a version record if the auditLog is enabled
  *
  * @param  Doctrine_Event $event
  * @return void
  */
 public function preUpdate(Doctrine_Event $event)
 {
     $disabled = $event->getInvoker()->hasMappedValue('disable_versioning') ? $event->getInvoker()->get('disable_versioning') : false;
     if (!$disabled) {
         parent::preUpdate($event);
     }
 }
Exemplo n.º 9
0
 public function __construct(Doctrine_Event $event, $when, $action, $parameters = array())
 {
     $invoker = $event->getInvoker();
     $parameters['record'] = $invoker;
     parent::__construct($invoker, sprintf('op_doctrine.%s_%s_%s', $when, $action, get_class($invoker)), $parameters);
     $this->doctrineEvent = $event;
 }
 public function preSave(Doctrine_Event $event)
 {
     $invoker = $event->getInvoker();
     $template = $invoker->getTable()->getTemplate('Doctrine_Template_GoogleI18n');
     $options = $template->getOptions();
     // get the first langauge that was changed
     foreach ($invoker->Translation as $lang => $translation) {
         if ($translation->isModified()) {
             $from = $lang;
             break;
         }
     }
     // skip if no translation was updated
     if (!isset($from)) {
         return true;
     }
     foreach ($options['languages'] as $to) {
         if ($to == $from) {
             continue;
         }
         foreach ($invoker->Translation[$to] as $field => $value) {
             if ($invoker->Translation->getTable()->isIdentifier($field)) {
                 continue;
             }
             $fromValue = $invoker->Translation[$from]->{$field};
             if ($options['skipEmpty'] && !$fromValue) {
                 continue;
             }
             $translatedValue = $template->getTranslation($from, $to, $fromValue);
             $invoker->Translation[$to]->{$field} = $translatedValue;
         }
     }
 }
 /**
  * preSave.
  *
  * @param Doctrine_Event $event
  */
 public function preSave($event)
 {
     $record = $event->getInvoker();
     if ($record->isNew()) {
         $file = $record->getFilename();
         if ($file != basename($file) && is_file($file)) {
             $fs = new lyMediaFileSystem();
             $dest_path = $record->getFolderPath();
             $dest_file = $fs->generateUniqueFileName($dest_path, basename($file));
             $fs->import($file, $dest_path . $dest_file);
             $record->setType(mime_content_type($file));
             $record->setFilename($dest_file);
         }
         if ($record->supportsThumbnails()) {
             lyMediaTools::generateThumbnails($record->getFolderPath(), $record->getFilename());
         }
     } else {
         $modified = $record->getModified(true);
         if (isset($modified['folder_id']) || isset($modified['filename'])) {
             //Selected new folder or edited filename: move/rename asset
             $dest_folder = Doctrine::getTable('lyMediaFolder')->find($record->getFolderId());
             $src_folder = $dest_folder;
             if (isset($modified['folder_id'])) {
                 $src_folder = Doctrine::getTable('lyMediaFolder')->find($modified['folder_id']);
             }
             $src = $src_folder->getRelativePath() . (isset($modified['filename']) ? $modified['filename'] : $record->getFileName());
             $dest = $dest_folder->getRelativePath() . $record->getFileName();
             $fs = new lyMediaFileSystem();
             $fs->rename($src, $dest, $record->supportsThumbnails());
         }
     }
 }
 public function preUpdate(Doctrine_Event $event)
 {
     $record = $event->getInvoker();
     if ($record->isModified()) {
         $this->denormalize($record);
     }
 }
Exemplo n.º 13
0
 public function preSave(Doctrine_Event $event)
 {
     $invoker = $event->getInvoker();
     $modified = $invoker->getModified();
     if ($invoker->isNew()) {
         // Check if the model is spam
         $akismet = $this->getAkismet($invoker);
         if ($akismet && (is_bool($akismet) || $akismet->isCommentSpam())) {
             $invoker->is_not_spam = false;
             $invoker->is_active = false;
         } else {
             $invoker->is_not_spam = true;
         }
     } else {
         if (isset($modified['is_not_spam'])) {
             $akismet = $this->getAkismet($invoker);
             if ($akismet) {
                 if (!$invoker->is_not_spam) {
                     $akismet->submitSpam();
                 } else {
                     $akismet->submitHam();
                 }
             }
         }
     }
 }
 /**
  * Deletes the object
  */
 public function postDelete(Doctrine_Event $event)
 {
     try {
         $this->deleteIndex($event->getInvoker());
     } catch (sfException $e) {
         // no context define, cannot do anything
     }
 }
Exemplo n.º 15
0
 /**
  * Set the geocodes automatically when a locatable object's locatable fields are modified
  *
  * @param Doctrine_Event $event
  * @return void
  * @author Brent Shaffer
  */
 public function preSave(Doctrine_Event $event)
 {
     $object = $event->getInvoker();
     $modified = array_keys($object->getModified());
     if (array_intersect($this->_options['fields'], $modified)) {
         $object->refreshGeocodes();
     }
 }
 /**
  * Automatically calculates the accuracy of an address. The accuracy is not 
  * recalculated unless the address changes.
  */
 public function preSave(Doctrine_Event $event)
 {
     $invoker = $event->getInvoker();
     $accuracy = $this->_options['accuracy']['name'];
     if ($invoker->{$accuracy} == Addressable::ACCURACY_PENDING || $invoker->isAddressModified()) {
         $invoker->calculateAccuracy();
     }
 }
Exemplo n.º 17
0
 public function preInsert(Doctrine_Event $event)
 {
     $name = $this->_options['name'];
     $record = $event->getInvoker();
     if (!$record->{$name}) {
         $record->{$name} = $this->buildSlug($record);
     }
 }
Exemplo n.º 18
0
 /**
  * preUpdate
  *
  * @param object $Doctrine_Event
  * @return void
  */
 public function preUpdate(Doctrine_Event $event)
 {
     $updatedName = $this->_options['updated']['name'];
     $modified = $event->getInvoker()->getModified();
     if (!isset($modified[$updatedName])) {
         $event->getInvoker()->{$updatedName} = self::getCurrentUserId();
     }
 }
Exemplo n.º 19
0
 /**
  * Prior to a record being deleted from the DB we delete it's config on disk. Note that the item's information is still in memory
  * while the delete transaction and records are running.
  * @param Doctrine_Event $event
  */
 public function postDelete(Doctrine_Event $event)
 {
     $invoker =& $event->getInvoker();
     $baseModel = Bluebox_Record::getBaseTransactionObject();
     $identifier = $invoker->identifier();
     // We do this because we can't set configs until we have saved all related models that may have an auto increment!
     TelephonyListener::$changedModels[$invoker->getOid()] = array('action' => 'delete', 'record' => &$invoker, 'baseModel' => $baseModel, 'identifier' => $identifier);
 }
 /**
  * Post-connect listener. Will set charset and run init queries if configured.
  *
  * @param      Doctrine_Event The Doctrine event object.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      1.0.4
  */
 public function postConnect(Doctrine_Event $event)
 {
     if ($this->database->hasParameter('charset')) {
         $event->getInvoker()->setCharset($this->database->getParameter('charset'));
     }
     foreach ((array) $this->database->getParameter('init_queries') as $query) {
         $event->getInvoker()->exec($query);
     }
 }
 public function postSave(Doctrine_Event $event)
 {
     $record = $event->getInvoker();
     if (array_key_exists($model = get_class($record), $this->configuration) && !$this->isRecordProcessed($record)) {
         $this->processCacheInvalidation($record, $this->configuration[$model]);
         $this->setRecordProcessed($record);
         $event->skipOperation();
     }
 }
Exemplo n.º 22
0
 /**
  * @param Doctrine_Event $event
  */
 public function postTransactionCommit(Doctrine_Event $event)
 {
     if ($event->getInvoker()->getConnection()->getTransactionLevel() == 1) {
         // process the file delete queue
         RokGallery_Queue_FileDelete::process();
         // process the Direcotry Delete queue
         RokGallery_Queue_DirectoryDelete::process();
     }
 }
 /**
  * Pre-save logic.
  *
  * Use preSave instead of preUpdate since the latter depends on the record's
  * state, which isn't necessarily dirty.
  *
  * @see Doctrine_Record_Listener
  */
 public function preSave(Doctrine_Event $event)
 {
     // this listener may have been added several times with a different $form instance
     // but as listeners have a model rather than a record scope we need to filter if
     // this current listener actually matches!
     if ($this->form->getObject()->id == $event->getInvoker()->id) {
         $this->doPreSave($event->getInvoker(), $this->form);
     }
 }
 public function preInsert(Doctrine_Event $pEvent)
 {
     // Set initial state
     $lInvoker = $pEvent->getInvoker();
     $lState = $this->getOption('column');
     if (!$lInvoker->{$lState}) {
         $lInvoker->{$lState} = $this->getOption('initial');
     }
 }
Exemplo n.º 25
0
 /**
  * parse the markdown in the specified fields when an object is updated
  *
  * @param Doctrine_Event $event
  * @return void
  * @author Brent Shaffer
  */
 public function preUpdate(Doctrine_Event $event)
 {
     $parser = new MarkdownExtra_Parser();
     $object = $event->getInvoker();
     foreach ($this->_options['fields'] as $parsedField => $markdownField) {
         if (array_key_exists($markdownField, $object->getModified())) {
             $object[$parsedField] = $parser->transform($object[$markdownField]);
         }
     }
 }
 public function postDelete(Doctrine_Event $event)
 {
     //if called from task do nothing
     if (!sfContext::hasInstance()) {
         return;
     }
     //delete from index
     $searchIndex = new zsSearchIndex($this->_options['index']);
     $searchIndex->updateIndex($event->getInvoker(), true);
 }
Exemplo n.º 27
0
 public function postInsert(Doctrine_Event $event)
 {
     if ('first' === $this->_options['new']) {
         $position = $event->getInvoker()->getTable()->createQuery('r')->select('MIN(r.position)')->fetchValue() - 1;
     } else {
         $position = $event->getInvoker()->get('id');
     }
     $event->getInvoker()->set('position', $position);
     $event->getInvoker()->save();
 }
Exemplo n.º 28
0
 /**
  * Executes save routine
  */
 public function postSave(Doctrine_Event $event)
 {
     if ($event->getInvoker()->doIndex()) {
         try {
             $this->saveIndex($event->getInvoker());
         } catch (sfException $e) {
             // no context define, cannot do anything,
         }
     }
 }
Exemplo n.º 29
0
 /**
  * Attachment Saving Logic
  *
  * @return void
  * @author Joshua Pruitt
  */
 public function preSave(Doctrine_Event $event)
 {
     $object = $event->getInvoker();
     //If the object is new, and attachments are set, save them
     if (!$object->getId() && isset($object['Attachments'])) {
         foreach ($object['Attachments'] as $attachment) {
             $object->addAttachment(new Attachment($attachment));
         }
     }
 }
Exemplo n.º 30
0
 /**
  * preUpdate
  *
  * @param Doctrine_Event $event 
  * @return void
  */
 public function preUpdate(Doctrine_Event $event)
 {
     if (false !== $this->_options['unique']) {
         $name = $this->_options['name'];
         $record = $event->getInvoker();
         if (!$record->{$name} || false !== $this->_options['canUpdate'] && array_key_exists($name, $record->getModified())) {
             $record->{$name} = $this->buildSlug($record);
         }
     }
 }