当前位置: 首页>>代码示例>>PHP>>正文


PHP db_transaction函数代码示例

本文整理汇总了PHP中db_transaction函数的典型用法代码示例。如果您正苦于以下问题:PHP db_transaction函数的具体用法?PHP db_transaction怎么用?PHP db_transaction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了db_transaction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _qwp_process_ops

function _qwp_process_ops(&$msg, &$data, &$msg_type, &$ret)
{
    global $FN_PROCESS_NEED_TRANSACTION;
    $ctx = false;
    if ($FN_PROCESS_NEED_TRANSACTION) {
        $ctx = db_transaction();
    }
    try {
        global $FN_PROCESS_OPS;
        if (isset($FN_PROCESS_OPS)) {
            if ($FN_PROCESS_OPS($msg, $data) !== false) {
                $msg_type = "info";
                $ret = true;
            }
        } else {
            $msg = L("No ops processor!");
        }
    } catch (PDOException $e) {
        if ($e->errorInfo[1] == 1062) {
            $msg = L("Duplicated record when doing ops, please check the parameters!");
        } else {
            $msg = L("Failed to execute query: ") . (IN_DEBUG ? $e->query_string : $e->getMessage());
        }
    } catch (Exception $e) {
        $msg = L("Exception happens: ") . $e->getMessage();
    }
    if ($ret !== true && $ctx) {
        $ctx->rollback();
    }
}
开发者ID:steem,项目名称:qwp,代码行数:30,代码来源:tmpl_json_ops.php

示例2: addComment

 function addComment($props)
 {
     if (!$props) {
         drupal_set_message(t('Insert requested with empty (filtered) data set'), 'error');
         return false;
     }
     //global $user;
     $txn = db_transaction();
     try {
         //$uid = $user->uid;
         //$props['author'] = $uid;
         $now = new DateTime();
         $props['date_posted'] = $now->format('Y-m-d H:i:s');
         // check for top level posts with an empty parent & set it to mysql null.
         if (!isset($props['parent_id']) || empty($props['parent_id'])) {
             $props['parent_id'] = null;
         }
         $result = FALSE;
         $query = db_insert(tableName('comment'))->fields($props);
         $id = $query->execute();
         if ($id) {
             $result = $id;
         } else {
             drupal_set_message(t('We could not add your comment'), 'error');
         }
     } catch (Exception $ex) {
         $txn->rollback();
         drupal_set_message(t('We could not add your comment. ') . (_DEBUG ? $ex->__toString() : ''), 'error');
     }
     return $result;
 }
开发者ID:edwinraycom,项目名称:vals-soc,代码行数:31,代码来源:ThreadedComments.php

示例3: dropDatasetStorage

    /**
     * @param DataControllerCallContext $callcontext
     * @param DatasetMetaData $dataset
     * @param DatasetStorageObserver[] $observers
     * @throws Exception
     */
    protected function dropDatasetStorage(DataControllerCallContext $callcontext, DatasetMetaData $dataset, array $observers = NULL) {
        MetaModelFactory::getInstance()->startGlobalModification();
        try {
            $transaction = db_transaction();
            try {
                if (isset($observers)) {
                    foreach ($observers as $observer) {
                        $observer->unregisterDataset($callcontext, $dataset, DatasetStorageObserver::STAGE__BEFORE);
                    }
                }

                // dropping physical storage of the dataset
                $request = new DatasetStorageRequest($dataset->name);
                LogHelper::log_debug($request);
                $this->datasourceStructureHandler->dropDatasetStorage($callcontext, $request);

                $dataset->used = FALSE;

                if (isset($observers)) {
                    foreach ($observers as $observer) {
                        $observer->unregisterDataset($callcontext, $dataset, DatasetStorageObserver::STAGE__AFTER);
                    }
                }
            }
            catch (Exception $e) {
                $transaction->rollback();
                throw $e;
            }
        }
        catch (Exception $e) {
            MetaModelFactory::getInstance()->finishGlobalModification(FALSE);
            throw $e;
        }
        MetaModelFactory::getInstance()->finishGlobalModification(TRUE);
    }
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:41,代码来源:DropDatasetStorageImpl.php

示例4: delete

 public function delete($ids, \DatabaseTransaction $transaction = NULL)
 {
     $transaction = isset($transaction) ? $transaction : db_transaction();
     try {
         parent::delete($ids, $transaction);
         db_delete('observers')->condition('observable_id', $ids, 'IN')->execute();
     } catch (\Exception $e) {
         watchdog_exception($this->entityType, $e);
         $transaction->rollback();
         throw $e;
     }
 }
开发者ID:TuWebO,项目名称:observable,代码行数:12,代码来源:ObservableStorageController.php

示例5: storeEvent

 /**
  * @param \Roomify\Bat\Event\Event $event
  * @param $granularity
  *
  * @return bool
  */
 public function storeEvent(Event $event, $granularity = Event::BAT_HOURLY)
 {
     $stored = TRUE;
     $transaction = db_transaction();
     try {
         // Itemize an event so we can save it
         $itemized = $event->itemize(new EventItemizer($event, $granularity));
         //Write days
         foreach ($itemized[Event::BAT_DAY] as $year => $months) {
             foreach ($months as $month => $days) {
                 db_merge($this->day_table_no_prefix)->key(array('unit_id' => $event->getUnitId(), 'year' => $year, 'month' => $month))->fields($days)->execute();
             }
         }
         if ($granularity == Event::BAT_HOURLY && isset($itemized[Event::BAT_HOUR])) {
             // Write Hours
             foreach ($itemized[Event::BAT_HOUR] as $year => $months) {
                 foreach ($months as $month => $days) {
                     foreach ($days as $day => $hours) {
                         // Count required as we may receive empty hours for granular events that start and end on midnight
                         if (count($hours) > 0) {
                             db_merge($this->hour_table_no_prefix)->key(array('unit_id' => $event->getUnitId(), 'year' => $year, 'month' => $month, 'day' => substr($day, 1)))->fields($hours)->execute();
                         }
                     }
                 }
             }
             //If we have minutes write minutes
             foreach ($itemized[Event::BAT_MINUTE] as $year => $months) {
                 foreach ($months as $month => $days) {
                     foreach ($days as $day => $hours) {
                         foreach ($hours as $hour => $minutes) {
                             db_merge($this->minute_table_no_prefix)->key(array('unit_id' => $event->getUnitId(), 'year' => $year, 'month' => $month, 'day' => substr($day, 1), 'hour' => substr($hour, 1)))->fields($minutes)->execute();
                         }
                     }
                 }
             }
         }
     } catch (\Exception $e) {
         $stored = FALSE;
         $transaction->rollback();
         watchdog_exception('BAT Event Save Exception', $e);
     }
     return $stored;
 }
开发者ID:roomify,项目名称:bat,代码行数:49,代码来源:DrupalDBStore.php

示例6: delete_single

 /**
  * Delete a user from the system. 
  *
  * This is a copy of user_delete() minus the user_load() call.
  */
 private function delete_single(stdClass $account)
 {
     $uids = array($account->uid);
     $transaction = db_transaction();
     try {
         module_invoke_all('user_delete', $account);
         module_invoke_all('entity_delete', $account, 'user');
         field_attach_delete('user', $account);
         drupal_session_destroy_uid($account->uid);
         db_delete('users')->condition('uid', $uids, 'IN')->execute();
         db_delete('users_roles')->condition('uid', $uids, 'IN')->execute();
         db_delete('authmap')->condition('uid', $uids, 'IN')->execute();
     } catch (Exception $e) {
         $transaction->rollback();
         watchdog_exception('user', $e);
         throw $e;
     }
     $this->resetCache($uids);
 }
开发者ID:vidiecan,项目名称:drupal_simple_ldap,代码行数:24,代码来源:SimpleLdapUserController.class.php

示例7: delete_multiple

 /**
  * Delete a list of memberships context entities.
  *
  * @param object $entities
  *   An array of memberships contexts to be deleted.
  */
 public function delete_multiple($entities)
 {
     $ids = array();
     if (!empty($entities)) {
         $transaction = db_transaction();
         try {
             foreach ($entities as $entity) {
                 module_invoke_all('lti_tool_provider_memberships_context_delete', $entity);
                 module_invoke_all('entity_delete', $entity, 'lti_tool_provider_memberships_context');
                 field_attach_delete('lti_tool_provider_memberships_context', $entity);
                 $ids[] = $entity->lti_tool_provider_memberships_context_id;
             }
             db_delete('lti_tool_provider_memberships_context')->condition('lti_tool_provider_memberships_context_id', $ids, 'IN')->execute();
         } catch (Exception $e) {
             $transaction->rollback();
             watchdog_exception('lti_tool_provider_memberships_context', $e);
             throw $e;
         }
     }
 }
开发者ID:kreynen,项目名称:elmsln,代码行数:26,代码来源:LTIToolProviderMembershipsContextEntityController.class.php

示例8: menuLinksRebuild

 /**
  * Perform menu-specific rebuilding.
  */
 protected function menuLinksRebuild()
 {
     if ($this->lock->acquire(__FUNCTION__)) {
         $transaction = db_transaction();
         try {
             // Ensure the menu links are up to date.
             $this->menuLinkManager->rebuild();
             // Ignore any database replicas temporarily.
             db_ignore_replica();
         } catch (\Exception $e) {
             $transaction->rollback();
             watchdog_exception('menu', $e);
         }
         $this->lock->release(__FUNCTION__);
     } else {
         // Wait for another request that is already doing this work.
         // We choose to block here since otherwise the router item may not
         // be available during routing resulting in a 404.
         $this->lock->wait(__FUNCTION__);
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:24,代码来源:MenuRouterRebuildSubscriber.php

示例9: ensureSubqueue

 /**
  * Makes sure that every simple queue has a subqueue.
  */
 protected function ensureSubqueue()
 {
     global $user;
     static $queues = array();
     if (!isset($queues[$this->queue->name])) {
         $queues[$this->queue->name] = TRUE;
         $transaction = db_transaction();
         $query = new EntityFieldQuery();
         $query->entityCondition('entity_type', 'entityqueue_subqueue')->entityCondition('bundle', $this->queue->name);
         $result = $query->execute();
         // If we don't have a subqueue already, create one now.
         if (empty($result['entityqueue_subqueue'])) {
             $subqueue = entityqueue_subqueue_create();
             $subqueue->queue = $this->queue->name;
             $subqueue->name = $this->queue->name;
             $subqueue->label = $this->getSubqueueLabel($subqueue);
             $subqueue->module = 'entityqueue';
             $subqueue->uid = $user->uid;
             entity_get_controller('entityqueue_subqueue')->save($subqueue, $transaction);
         }
     }
 }
开发者ID:dalia-m-elsayed,项目名称:spica,代码行数:25,代码来源:SimpleEntityQueueHandler.class.php

示例10: menuLinksRebuild

 /**
  * Perform menu-specific rebuilding.
  */
 protected function menuLinksRebuild()
 {
     if ($this->lock->acquire(__FUNCTION__)) {
         $transaction = db_transaction();
         try {
             // Ensure the menu links are up to date.
             menu_link_rebuild_defaults();
             // Clear the menu cache.
             menu_cache_clear_all();
             // Track which menu items are expanded.
             _menu_update_expanded_menus();
         } catch (\Exception $e) {
             $transaction->rollback();
             watchdog_exception('menu', $e);
         }
         $this->lock->release(__FUNCTION__);
     } else {
         // Wait for another request that is already doing this work.
         // We choose to block here since otherwise the router item may not
         // be available during routing resulting in a 404.
         $this->lock->wait(__FUNCTION__);
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:26,代码来源:RouterRebuildSubscriber.php

示例11: disableDatasetStorage

    /**
     * @param DataControllerCallContext $callcontext
     * @param DatasetMetaData $dataset
     * @param DatasetStorageObserver[] $observers
     * @throws Exception
     */
    protected function disableDatasetStorage(DataControllerCallContext $callcontext, DatasetMetaData $dataset, array $observers = NULL) {
        MetaModelFactory::getInstance()->startGlobalModification();
        try {
            $transaction = db_transaction();
            try {
                $dataset->used = FALSE;

                if (isset($observers)) {
                    foreach ($observers as $observer) {
                        $observer->disableDataset($callcontext, $dataset);
                    }
                }
            }
            catch (Exception $e) {
                $transaction->rollback();
                throw $e;
            }
        }
        catch (Exception $e) {
            MetaModelFactory::getInstance()->finishGlobalModification(FALSE);
            throw $e;
        }
        MetaModelFactory::getInstance()->finishGlobalModification(TRUE);
    }
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:30,代码来源:DisableDatasetImpl.php

示例12: __construct

 public function __construct($message, $tag, $module, $variables = array(), $name = NULL, array $options = array())
 {
     $this->message = $message;
     $this->tag = $tag;
     $this->module = $module;
     $this->variables = $variables;
     $this->txn = db_transaction($name, $options);
 }
开发者ID:zevergreenz,项目名称:Drupal,代码行数:8,代码来源:cvwobase_d7_db_api.php

示例13: db_import

/**
 * Import SQL from the file.
 *
 * @param string $file
 *
 * @return int
 */
function db_import($file)
{
    if ($fp = fopen($file, 'r')) {
        $sql = '';
        $i = 0;
        $flag = true;
        db_transaction();
        while ($line = fgets($fp)) {
            $line = str_replace("\r\n", "\n", $line);
            $line = str_replace("\r", "\n", $line);
            if ((substr_count($line, '\'') - substr_count($line, '\\\'')) % 2 !== 0) {
                $flag = !$flag;
            }
            $sql .= $line;
            if (preg_match('/;$/', trim($line)) && $flag) {
                $resource = db_query($sql);
                if (!$resource) {
                    db_rollback();
                    if (LOGGING_MESSAGE) {
                        logging('message', 'db: Query error: ' . db_error());
                    }
                    error('db: Query error' . (DEBUG_LEVEL ? ': ' . db_error() : ''));
                }
                $sql = '';
                $i++;
            }
        }
        fclose($fp);
        db_commit();
    } else {
        error('db: Import file can\'t read');
    }
    return $i;
}
开发者ID:refirio,项目名称:levis,代码行数:41,代码来源:db.php

示例14: updateProperties

    /**
     * @param DataControllerCallContext $callcontext
     * @param DatasetMetaData $originalDataset
     * @param DatasetMetaData $modifiedDataset
     * @param DatasetStorageObserver[] $observers
     * @throws Exception
     */
    protected function updateProperties(DataControllerCallContext $callcontext, DatasetMetaData $originalDataset, DatasetMetaData $modifiedDataset, array $observers = NULL) {
        $justPersistedColumns = NULL;
        ArrayHelper::merge($justPersistedColumns, $callcontext->changeAction->newIncludedColumns);
        ArrayHelper::merge($justPersistedColumns, $callcontext->changeAction->restoredColumns);
        ArrayHelper::merge($justPersistedColumns, $callcontext->changeAction->updatedDataTypeIncludedColumns);

        $columns = $justPersistedColumns;
        ArrayHelper::merge($columns, $callcontext->changeAction->updatedColumns);
        if ($callcontext->changeAction->isDatasetUpdated || isset($columns) || $callcontext->changeAction->isKeyUpdated) {
            MetaModelFactory::getInstance()->startGlobalModification();
            try {
                $transaction = db_transaction();
                try {
                    if (isset($columns)) {
                        foreach ($columns as $column) {
                            if (isset($justPersistedColumns[$column->name])) {
                                $column->used = TRUE;
                            }

                            if (isset($callcontext->changeAction->updatedColumns[$column->name])) {
                                $modifiedColumn = $modifiedDataset->getColumn($column->name);

                                $column->publicName = $modifiedColumn->publicName;
                                $column->description = $modifiedColumn->description;
                                $column->source = $modifiedColumn->source;
                                $column->key = $modifiedColumn->key;
                            }

                            if (isset($observers)) {
                                foreach ($observers as $observer) {
                                    $observer->updateColumn($callcontext, $originalDataset, $column->name);
                                }
                            }
                        }
                    }

                    if ($callcontext->changeAction->isDatasetUpdated) {
                        $originalDataset->publicName = $modifiedDataset->publicName;
                        $originalDataset->description = $modifiedDataset->description;
                        $originalDataset->initializeSourceFrom($modifiedDataset->source, TRUE);
                        $originalDataset->initializeAliasesFrom($modifiedDataset->aliases, TRUE);

                        if (isset($observers)) {
                            foreach ($observers as $observer) {
                                $observer->updateDataset($callcontext, $originalDataset);
                            }
                        }
                    }

                    if ($callcontext->changeAction->isKeyUpdated) {
                        $modifiedDatasetKeyColumnNames = $modifiedDataset->findKeyColumnNames();
                        if (isset($modifiedDatasetKeyColumnNames)) {
                            $this->executeDatasetUpdateOperations(
                                $callcontext,
                                $originalDataset,
                                array(new CreateDatasetKeyOperation()));
                        }
                    }
                }
                catch (Exception $e) {
                    $transaction->rollback();
                    throw $e;
                }
            }
            catch (Exception $e) {
                MetaModelFactory::getInstance()->finishGlobalModification(FALSE);
                throw $e;
            }
            MetaModelFactory::getInstance()->finishGlobalModification(TRUE);
        }
    }
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:78,代码来源:ModifyDatasetStorageImpl.php

示例15: update

    protected function update(Import\ImportStream $stream, Import\ImportContext $context) {
        $datasets = $stream->get('datasets');
        if (empty($datasets)) {
            return;
        }

        gd_datasource_set_active($context->get('datasourceName'));
        $metamodel = data_controller_get_metamodel();

        $environment_metamodel = data_controller_get_environment_metamodel();
        $datasource = $environment_metamodel->getDataSource($context->get('datasourceName'));

        foreach ( $datasets as $dataset ) {
            $existingDataset = GD_DatasetMetaModelLoaderHelper::findDatasetByUUID($metamodel->datasets, $dataset->uuid);
            if ( !$existingDataset ) {

                // map for re-linking dependent objects
                $dataset->originalName = $dataset->name;

                // create new name
                $newDatasetName = GD_NamingConvention::generateDatasetName();
                $dataset->name = $newDatasetName;
                $dataset->source = $newDatasetName;
                $dataset->datasourceName = $datasource->name;
            } else {
                // map for re-linking dependent objects
                $dataset->originalName = $dataset->name;

                $dataset->name = $existingDataset->name;
                $dataset->source = $existingDataset->source;
                $dataset->datasourceName = $existingDataset->datasourceName;
            }
        }

        // prepare dataset columns for import
        $this->prepareColumns($datasets);

        // prepares the metadata object, has to be of type RecordMetaData
        foreach ( $datasets as $key => $dataset ) {
            $metadata = new DatasetMetaData();
            $metadata->initializeFrom($dataset);
            $datasets[$key] = $metadata;
        }

        // ensure datasets are created in order to satisfy dependencies
        usort($datasets, array(new ReferencedDatasetComparator(), 'compare'));

        foreach ( $datasets as $dataset ) {
            $existingDataset = GD_DatasetMetaModelLoaderHelper::findDatasetByUUID($metamodel->datasets, $dataset->uuid);
            if ($existingDataset) {
                gd_data_controller_ddl_modify_dataset($dataset);
            } else {
                MetaModelFactory::getInstance()->startGlobalModification();
                try {
                    $transaction = db_transaction();
                    try {
                        gd_data_controller_ddl_create_dataset($dataset);
                    } catch (Exception $e) {
                        $transaction->rollback();
                        throw $e;
                    }
                } catch (Exception $e) {
                    MetaModelFactory::getInstance()->finishGlobalModification(false);
                    throw $e;
                }
                MetaModelFactory::getInstance()->finishGlobalModification(true);
            }
        }

        $stream->set('datasets',$datasets);
    }
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:71,代码来源:DatasetImport.php


注:本文中的db_transaction函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。