本文整理汇总了PHP中db_rollback函数的典型用法代码示例。如果您正苦于以下问题:PHP db_rollback函数的具体用法?PHP db_rollback怎么用?PHP db_rollback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_rollback函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteByInvoice
/**
* Delete all items for a invoice
*
* @param Invoice $invoice
* @return null
*/
function deleteByInvoice($invoice)
{
db_begin_work();
$execute = db_execute('DELETE FROM ' . TABLE_PREFIX . 'invoice_time_records WHERE invoice_id = ?', $invoice->getId());
if ($execute && !is_error($execute)) {
$delete = InvoiceItems::delete(array('invoice_id = ?', $invoice->getId()));
if ($delete && !is_error($delete)) {
db_commit();
} else {
db_rollback();
}
// if
return $delete;
} else {
db_rollback();
return $execute;
}
// if
}
示例2: setDefault
/**
* Set $currency as default
*
* @param Currency $currency
* @return boolean
*/
function setDefault($currency)
{
if ($currency->getIsDefault()) {
return true;
}
// if
db_begin_work();
$currency->setIsDefault(true);
$update = $currency->save();
if ($update && !is_error($update)) {
$update = db_execute('UPDATE ' . TABLE_PREFIX . 'currencies SET is_default = ? WHERE id != ?', false, $currency->getId());
cache_remove_by_pattern(TABLE_PREFIX . 'currencies_id_*');
if ($update && !is_error($update)) {
db_commit();
return true;
}
// if
}
// if
db_rollback();
return $update;
}
示例3: login_submit
/**
* Called when the login form is submitted. Validates the user and password, and
* if they are valid, starts a new session for the user.
*
* @param object $form The Pieform form object
* @param array $values The submitted values
* @access private
*/
function login_submit(Pieform $form, $values)
{
global $SESSION, $USER;
$username = trim($values['login_username']);
$password = $values['login_password'];
$authenticated = false;
try {
$authenticated = $USER->login($username, $password);
if (empty($authenticated)) {
$SESSION->add_error_msg(get_string('loginfailed'));
return;
}
} catch (AuthUnknownUserException $e) {
// If the user doesn't exist, check for institutions that
// want to create users automatically.
try {
// Reset the LiveUser object, since we are attempting to create a
// new user
$SESSION->destroy_session();
$USER = new LiveUser();
$authinstances = get_records_sql_array("\n SELECT a.id, a.instancename, a.priority, a.authname, a.institution, i.suspended, i.displayname\n FROM {institution} i JOIN {auth_instance} a ON a.institution = i.name\n WHERE a.authname != 'internal'\n ORDER BY a.institution, a.priority, a.instancename", null);
if ($authinstances == false) {
throw new AuthUnknownUserException("\"{$username}\" is not known");
}
$USER->username = $username;
reset($authinstances);
while ((list(, $authinstance) = each($authinstances)) && false == $authenticated) {
$auth = AuthFactory::create($authinstance->id);
if (!$auth->can_auto_create_users()) {
continue;
}
// catch semi-fatal auth errors, but allow next auth instance to be
// tried
try {
if ($auth->authenticate_user_account($USER, $password)) {
$authenticated = true;
} else {
continue;
}
} catch (AuthInstanceException $e) {
continue;
}
// Check now to see if the institution has its maximum quota of users
require_once 'institution.php';
$institution = new Institution($authinstance->institution);
if ($institution->isFull()) {
$institution->send_admin_institution_is_full_message();
throw new AuthUnknownUserException('Institution has too many users');
}
$USER->authinstance = $authinstance->id;
$userdata = $auth->get_user_info($username);
if (empty($userdata)) {
throw new AuthUnknownUserException("\"{$username}\" is not known");
}
// Check for a suspended institution
if ($authinstance->suspended) {
$sitename = get_config('sitename');
throw new AccessTotallyDeniedException(get_string('accesstotallydenied_institutionsuspended', 'mahara', $authinstance->displayname, $sitename));
}
// We have the data - create the user
$USER->lastlogin = db_format_timestamp(time());
if (isset($userdata->firstname)) {
$USER->firstname = sanitize_firstname($userdata->firstname);
}
if (isset($userdata->lastname)) {
$USER->lastname = sanitize_firstname($userdata->lastname);
}
if (isset($userdata->email)) {
$USER->email = sanitize_email($userdata->email);
} else {
// The user will be asked to populate this when they log in.
$USER->email = null;
}
$profilefields = array();
foreach (array('studentid', 'preferredname') as $pf) {
if (isset($userdata->{$pf})) {
$sanitize = 'sanitize_' . $pf;
if (($USER->{$pf} = $sanitize($userdata->{$pf})) !== '') {
$profilefields[$pf] = $USER->{$pf};
}
}
}
try {
// If this authinstance is a parent auth for some xmlrpc authinstance, pass it along to create_user
// so that this username also gets recorded as the username for sso from the remote sites.
$remoteauth = $auth->is_parent_authority();
create_user($USER, $profilefields, $institution, $remoteauth);
$USER->reanimate($USER->id, $authinstance->id);
} catch (Exception $e) {
db_rollback();
throw $e;
}
//.........这里部分代码省略.........
示例4: delete
/**
* Delete this company from database
*
* @param void
* @return boolean
*/
function delete()
{
db_begin_work();
$delete = parent::delete();
if ($delete && !is_error($delete)) {
cache_remove('companies_id_name');
// remove ID - name map from cache
$users = $this->getUsers();
if (is_foreachable($users)) {
foreach ($users as $user) {
$user->delete();
}
// foreach
}
// if
Projects::resetByCompany($this);
db_commit();
} else {
db_rollback();
}
// if
return $delete;
}
示例5: FRSFile
//exec($cmd,$output);
$userfile_name = $ftp_filename;
$userfile = $upload_dir . '/' . $ftp_filename;
//echo $cmd.'***'.$output.'***'.$userfile;
}
//
// Now create the new FRSFile in the db
//
$frsf = new FRSFile($frsr);
if (!$frsf || !is_object($frsf)) {
exit_error('Error', 'Could Not Get FRSFile');
} elseif ($frsf->isError()) {
exit_error('Error', $frsf->getErrorMessage());
} else {
if (!$frsf->create($userfile_name, $userfile['tmp_name'], $type_id, $processor_id, $release_date)) {
db_rollback();
exit_error('Error', $frsf->getErrorMessage());
}
$feedback = _('File Released');
}
}
}
// Edit/Delete files in a release
if (getStringFromRequest('step3')) {
$step3 = getStringFromRequest('step3');
$file_id = getIntFromRequest('file_id');
$processor_id = getIntFromRequest('processor_id');
$type_id = getIntFromRequest('type_id');
$new_release_id = getIntFromRequest('new_release_id');
$release_time = getStringFromRequest('release_time');
$group_id = getIntFromRequest('group_id');
示例6: import_next_user
function import_next_user($filename, $username, $authinstance)
{
global $ADDEDUSERS, $FAILEDUSERS;
log_debug('adding user ' . $username . ' from ' . $filename);
$authobj = get_record('auth_instance', 'id', $authinstance);
$institution = new Institution($authobj->institution);
$date = time();
$nicedate = date('Y/m/d h:i:s', $date);
$niceuser = preg_replace('/[^a-zA-Z0-9_-]/', '-', $username);
$uploaddir = get_config('dataroot') . 'import/' . $niceuser . '-' . $date . '/';
check_dir_exists($uploaddir);
// Unzip the file
$archive = new ZipArchive();
if ($archive->open($filename) && $archive->extractTo($uploaddir)) {
// successfully extracted
$archive->close();
} else {
$FAILEDUSERS[$username] = get_string('unzipfailed', 'admin', hsc($filename));
return;
}
$leap2afilename = $uploaddir . 'leap2a.xml';
if (!is_file($leap2afilename)) {
$FAILEDUSERS[$username] = get_string('noleap2axmlfiledetected', 'admin');
log_debug($FAILEDUSERS[$username]);
return;
}
// If the username is already taken, append something to the end
while (get_record('usr', 'username', $username)) {
$username .= "_";
}
$user = (object) array('authinstance' => $authinstance, 'username' => $username, 'firstname' => 'Imported', 'lastname' => 'User', 'password' => get_random_key(6), 'passwordchange' => 1);
db_begin();
try {
$user->id = create_user($user, array(), $institution, $authobj);
} catch (EmailException $e) {
// Suppress any emails (e.g. new institution membership) sent out
// during user creation, becuase the user doesn't have an email
// address until we've imported them from the Leap2A file.
log_debug("Failed sending email during user import");
}
$niceuser = preg_replace('/[^a-zA-Z0-9_-]/', '-', $user->username);
$record = (object) array('token' => '', 'usr' => $user->id, 'queue' => (int) (!PluginImport::import_immediately_allowed()), 'ready' => 0, 'expirytime' => db_format_timestamp(time() + 60 * 60 * 24), 'format' => 'leap', 'data' => array('importfile' => $filename, 'importfilename' => $filename, 'importid' => $niceuser . time(), 'mimetype' => file_mime_type($filename)), 'loglevel' => PluginImportLeap::LOG_LEVEL_VERBOSE, 'logtargets' => LOG_TARGET_FILE, 'profile' => true);
$tr = new LocalImporterTransport($record);
$tr->extract_file();
$importer = PluginImport::create_importer(null, $tr, $record);
unset($record, $tr);
try {
$importer->process();
log_info("Imported user account {$user->id} from Leap2A file, see" . $importer->get('logfile') . 'for a full log');
} catch (ImportException $e) {
log_info("Leap2A import failed: " . $e->getMessage());
$FAILEDUSERS[$username] = get_string("leap2aimportfailed");
db_rollback();
}
db_commit();
if (empty($FAILEDUSERS[$username])) {
// Reload the user details, as various fields are changed by the
// importer when importing (e.g. firstname/lastname)
$newuser = get_record('usr', 'id', $user->id);
$newuser->clearpasswd = $user->password;
$ADDEDUSERS[] = $newuser;
}
return;
}
示例7: delete
/**
*
*
*/
function delete($sure, $really_sure)
{
if (!$sure || !$really_sure) {
$this->setMissingParamsError();
return false;
}
if (!$this->ArtifactType->userIsAdmin()) {
$this->setPermissionDeniedError();
return false;
}
db_begin();
$sql = "DELETE FROM artifact_extra_field_data \n\t\t\tWHERE extra_field_id='" . $this->getID() . "'";
$result = db_query($sql);
if ($result) {
$sql = "DELETE FROM artifact_extra_field_elements\n\t\t\t\tWHERE extra_field_id='" . $this->getID() . "'";
$result = db_query($sql);
if ($result) {
$sql = "DELETE FROM artifact_extra_field_list\n WHERE extra_field_id='" . $this->getID() . "'";
$result = db_query($sql);
if ($result) {
if ($this->getType() == ARTIFACT_EXTRAFIELDTYPE_STATUS) {
if (!$this->ArtifactType->setCustomStatusField(0)) {
db_rollback();
return false;
}
}
db_commit();
return true;
} else {
$this->setError(db_error());
db_rollback();
return false;
}
} else {
$this->setError(db_error());
db_rollback();
return false;
}
} else {
$this->setError(db_error());
db_rollback();
return false;
}
}
示例8: analyze_message
/**
* Find project objects in commit message, make them links and
* save the relations to database
*
* @param string $commit_message
* @param string $commit_author
* @param integer $revision
* @param Repository $repository
* @param Project $project
* @return string
*/
function analyze_message($commit_message, $commit_author, $revision, $repository, $project)
{
if (define('PURIFY_HTML') && PURIFY_HTML) {
$commit_message = purify_html($commit_message);
// Clean!
}
// if
$pattern = '/((complete[d]*)[\\s]+)?(ticket|milestone|discussion|task)[s]*[\\s]+[#]*\\d+/i';
if (preg_match_all($pattern, $commit_message, $matches)) {
$i = 0;
$search = array();
$replace = array();
$matches_unique = array_unique($matches['0']);
foreach ($matches_unique as $key => $match) {
$match_data = preg_split('/[\\s,]+/', $match, null, PREG_SPLIT_NO_EMPTY);
// check if the object got completed by this commit
$object_completed = false;
if (strpos(strtolower($match_data['0']), 'complete') !== false) {
$object_completed = true;
unset($match_data['0']);
$match_data = array_values($match_data);
}
// if
$object_class_name = $match_data['0'];
$module_name = Inflector::pluralize($object_class_name);
$object_id = trim($match_data['1'], '#');
$search[$i] = $match;
if (class_exists($module_name) && class_exists($object_class_name)) {
$object = null;
switch (strtolower($module_name)) {
case 'tickets':
$object = Tickets::findByTicketId($project, $object_id);
break;
case 'discussions':
$object = Discussions::findById($object_id);
break;
case 'milestones':
$object = Milestones::findById($object_id);
break;
case 'tasks':
$object = Tasks::findById($object_id);
break;
}
// switch
if (instance_of($object, $object_class_name)) {
$link_already_created = CommitProjectObjects::count("object_id = '" . $object->getId() . "' AND revision = '{$revision}'") > 0;
if (!$link_already_created) {
$comit_project_object = new CommitProjectObject();
$comit_project_object->setProjectId($object->getProjectId());
$comit_project_object->setObjectId($object->getId());
$comit_project_object->setObjectType(ucfirst($object_class_name));
$comit_project_object->setRepositoryId($repository->getId());
$comit_project_object->setRevision($revision);
db_begin_work();
$save = $comit_project_object->save();
if ($save && !is_error($save)) {
db_commit();
} else {
db_rollback();
}
// if save
}
// if
$replace[$i] = ($object_completed ? 'Completed ' : '') . '<a href="' . $object->getViewUrl() . '">' . $match_data['0'] . ' ' . $match_data['1'] . '</a>';
// set the object as completed
if ($object_completed && !instance_of($object, 'Discussion')) {
$completed_by = $repository->getMappedUser($commit_author);
$object->complete($completed_by);
}
// if
} else {
$replace[$i] = ($object_completed ? 'Completed ' : '') . '<a href="#" class="project_object_missing" title="' . lang('Project object does not exist in this project') . '">' . $match_data['0'] . ' ' . $match_data['1'] . '</a>';
}
// if instance_of
$i++;
}
// if module loaded
}
// foreach
return str_ireplace($search, $replace, htmlspecialchars($commit_message));
// linkify
}
// if preg_match
return $commit_message;
}
示例9: edit
/**
* Show and process edit attachment form
*
* @param void
* @return null
*/
function edit()
{
$this->wireframe->print_button = false;
if ($this->active_attachment->isNew()) {
$this->httpError(HTTP_ERR_NOT_FOUND);
}
// if
$parent = $this->active_attachment->getParent();
if (!instance_of($parent, 'ProjectObject')) {
$this->httpError(HTTP_ERR_NOT_FOUND);
}
// if
$attachment_data = $this->request->post('attachment');
if (!is_array($attachment_data)) {
$attachment_data = array('name' => $this->active_attachment->getName());
}
// if
$this->smarty->assign('attachment_data', $attachment_data);
if ($this->request->isSubmitted()) {
db_begin_work();
$old_name = $this->active_attachment->getName();
$this->active_attachment->setName(array_var($attachment_data, 'name'));
$save = $this->active_attachment->save();
if ($save && !is_error($save)) {
db_commit();
$this->active_attachment->ready();
if ($this->request->getFormat() == FORMAT_HTML) {
flash_success('File :filename has been updated', array('filename' => $old_name));
$this->redirectToUrl($parent->getViewUrl());
} else {
$this->serveData($this->active_attachment);
}
// if
} else {
db_rollback();
if ($this->request->getFormat() == FORMAT_HTML) {
flash_error('Failed to update :filename', array('filename' => $old_name));
$this->redirectToUrl($parent->getViewUrl());
} else {
$this->serveData($save);
}
// if
}
// if
}
// if
}
示例10: delete
/**
* Delete from database
*
* @param void
* @return boolean
*/
function delete()
{
db_begin_work();
$delete = parent::delete();
if ($delete && !is_error($delete)) {
unlink($this->getAvatarPath());
unlink($this->getAvatarPath(true));
ProjectUsers::deleteByUser($this);
Assignments::deleteByUser($this);
Subscriptions::deleteByUser($this);
StarredObjects::deleteByUser($this);
PinnedProjects::deleteByUser($this);
UserConfigOptions::deleteByUser($this);
Reminders::deleteByUser($this);
search_index_remove($this->getId(), 'User');
$cleanup = array();
event_trigger('on_user_cleanup', array(&$cleanup));
if (is_foreachable($cleanup)) {
foreach ($cleanup as $table_name => $fields) {
foreach ($fields as $field) {
$condition = '';
if (is_array($field)) {
$id_field = array_var($field, 'id');
$name_field = array_var($field, 'name');
$email_field = array_var($field, 'email');
$condition = array_var($field, 'condition');
} else {
$id_field = $field . '_id';
$name_field = $field . '_name';
$email_field = $field . '_email';
}
// if
if ($condition) {
db_execute('UPDATE ' . TABLE_PREFIX . "{$table_name} SET {$id_field} = 0, {$name_field} = ?, {$email_field} = ? WHERE {$id_field} = ? AND {$condition}", $this->getName(), $this->getEmail(), $this->getId());
} else {
db_execute('UPDATE ' . TABLE_PREFIX . "{$table_name} SET {$id_field} = 0, {$name_field} = ?, {$email_field} = ? WHERE {$id_field} = ?", $this->getName(), $this->getEmail(), $this->getId());
}
// if
}
// foreach
}
// foreach
}
// if
db_commit();
return true;
} else {
db_rollback();
return $delete;
}
// if
}
示例11: viewlayout_submit
function viewlayout_submit(Pieform $form, $values)
{
global $view, $SESSION, $new, $layoutrows, $layoutcolumns;
$oldrows = $view->get('numrows');
$oldlayout = $view->get_layout();
$newlayout = $values['layoutselect'];
if (!isset($layoutrows[$newlayout])) {
throw new ParamOutOfRangeException(get_string('invalidlayoutselection', 'error', $action));
} else {
$newrows = count($layoutrows[$newlayout]);
}
db_begin();
// for each existing row which will still exist after the update, check whether to add or remove columns
for ($i = 0; $i < min(array($oldrows, $newrows)); $i++) {
// compare oldlayout column structure with newlayout
$oldcolumns = $oldlayout->rows[$i + 1]['columns'];
$newcolumnindex = $layoutrows[$newlayout][$i + 1];
$newcolumns = $layoutcolumns[$newcolumnindex]->columns;
// Specify row when adding or removing columns
if ($oldcolumns > $newcolumns) {
for ($j = $oldcolumns; $j > $newcolumns; $j--) {
$view->removecolumn(array('row' => $i + 1, 'column' => $j));
}
} else {
if ($oldcolumns < $newcolumns) {
for ($j = $oldcolumns; $j < $newcolumns; $j++) {
$view->addcolumn(array('row' => $i + 1, 'before' => $j + 1, 'returndata' => false));
}
}
}
$dbcolumns = get_field('view_rows_columns', 'columns', 'view', $view->get('id'), 'row', $i + 1);
if ($dbcolumns != $newcolumns) {
db_rollback();
$SESSION->add_error_msg(get_string('changecolumnlayoutfailed', 'view'));
redirect(get_config('wwwroot') . 'view/layout.php?id=' . $view->get('id') . ($new ? '&new=1' : ''));
}
}
// add or remove rows and move content accordingly if required
if ($oldrows > $newrows) {
for ($i = $oldrows; $i > $newrows; $i--) {
$view->removerow(array('row' => $i, 'layout' => $oldlayout));
}
} else {
if ($oldrows < $newrows) {
for ($i = $oldrows; $i < $newrows; $i++) {
$view->addrow(array('before' => $i + 1, 'newlayout' => $newlayout, 'returndata' => false));
}
}
}
if ($view->get('numrows') != $newrows) {
db_rollback();
$SESSION->add_error_msg(get_string('changerowlayoutfailed', 'view'));
redirect(get_config('wwwroot') . 'view/layout.php?id=' . $view->get('id') . ($new ? '&new=1' : ''));
}
db_commit();
$view->set('layout', $newlayout);
$view->commit();
$SESSION->add_ok_msg(get_string('viewlayoutchanged', 'view'));
redirect('/view/blocks.php?id=' . $view->get('id') . ($new ? '&new=1' : ''));
}
示例12: create
/**
* create - use this function to create a new entry in the database.
*
* @param string The name of the mailing list
* @param string The description of the mailing list
* @param int Pass (1) if it should be public (0) for private.
*
* @return boolean success.
*/
function create($listName, $description, $isPublic = MAIL__MAILING_LIST_IS_PUBLIC, $creator_id = false)
{
//
// During the group creation, the current user_id will not match the admin's id
//
if (!$creator_id) {
$creator_id = user_getid();
if (!$this->userIsAdmin()) {
$this->setPermissionDeniedError();
return false;
}
}
if (!$listName || strlen($listName) < MAIL__MAILING_LIST_NAME_MIN_LENGTH) {
$this->setError(_('Must Provide List Name That Is 4 or More Characters Long'));
return false;
}
$realListName = strtolower($this->Group->getUnixName() . '-' . $listName);
if (!validate_email($realListName . '@' . $GLOBALS['sys_lists_host'])) {
$this->setError(_('Invalid List Name') . ': ' . $realListName . '@' . $GLOBALS['sys_lists_host']);
return false;
}
$result = db_query('SELECT 1 FROM mail_group_list WHERE lower(list_name)=\'' . $realListName . '\'');
if (db_numrows($result) > 0) {
$this->setError(_('List Already Exists'));
return false;
}
$result_forum_samename = db_query('SELECT 1 FROM forum_group_list WHERE forum_name=\'' . $listName . '\' AND group_id=' . $this->Group->getID() . '');
if (db_numrows($result_forum_samename) > 0) {
$this->setError(_('Forum exists with the same name'));
return false;
}
$listPassword = substr(md5($GLOBALS['session_hash'] . time() . rand(0, 40000)), 0, 16);
$sql = 'INSERT INTO mail_group_list ' . '(group_id, list_name, is_public, password, list_admin, status, description) VALUES (' . $this->Group->getID() . ', ' . "'" . $realListName . "'," . "'" . $isPublic . "'," . "'" . $listPassword . "'," . "'" . $creator_id . "'," . "'" . MAIL__MAILING_LIST_IS_REQUESTED . "'," . "'" . $description . "')";
db_begin();
$result = db_query($sql);
if (!$result) {
db_rollback();
$this->setError(sprintf(_('Error Creating %1$s'), _('Error Creating %1$s')) . db_error());
return false;
}
$this->groupMailingListId = db_insertid($result, 'mail_group_list', 'group_list_id');
$this->fetchData($this->groupMailingListId);
$user =& user_get_object($creator_id);
$userEmail = $user->getEmail();
if (empty($userEmail) || !validate_email($userEmail)) {
db_rollback();
$this->setInvalidEmailError();
return false;
} else {
$mailBody = stripcslashes(sprintf(_('A mailing list will be created on %1$s in 6-24 hours
and you are the list administrator.
This list is: %3$s@%2$s .
Your mailing list info is at:
%4$s .
List administration can be found at:
%5$s .
Your list password is: %6$s .
You are encouraged to change this password as soon as possible.
Thank you for registering your project with %1$s.
-- the %1$s staff
'), $GLOBALS['sys_name'], $GLOBALS['sys_lists_host'], $realListName, $this->getExternalInfoUrl(), $this->getExternalAdminUrl(), $listPassword));
$mailSubject = sprintf(_('%1$s New Mailing List'), $GLOBALS['sys_name']);
util_send_message($userEmail, $mailSubject, $mailBody, 'admin@' . $GLOBALS['sys_default_domain']);
}
db_commit();
return true;
}
示例13: delete
/**
* Delete document
*
* @param void
* @return null
*/
function delete()
{
$filepath = $this->getFilePath();
db_begin_work();
$delete = parent::delete();
if (!$delete || is_error($delete)) {
db_rollback();
return $delete;
}
// if
$delete_attachments = Attachments::deleteByObject($this);
if (!$delete_attachments || is_error($delete_attachments)) {
db_rollback();
return $delete_attachments;
}
// if
if (is_file($filepath)) {
@unlink($filepath);
}
// if
db_commit();
return true;
}
示例14: edit
/**
* Edit repository
*
* @param null
* @return void
*/
function edit()
{
if (!$this->active_repository->canEdit($this->logged_user)) {
$this->httpError(HTTP_ERR_FORBIDDEN);
}
// if
$repository_data = $this->request->post('repository');
if (!is_array($repository_data)) {
$repository_data = array('name' => $this->active_repository->getName(), 'url' => $this->active_repository->getUrl(), 'username' => $this->active_repository->getUsername(), 'password' => $this->active_repository->getPassword(), 'repositorytype' => $this->active_repository->getRepositoryType(), 'updatetype' => $this->active_repository->getUpdateType(), 'visibility' => $this->active_repository->getVisibility());
}
if ($this->request->isSubmitted()) {
db_begin_work();
$this->active_repository->setAttributes($repository_data);
$this->active_repository->loadEngine($this->active_repository->getRepositoryType());
$this->repository_engine = new RepositoryEngine($this->active_repository);
$this->repository_engine->triggerred_by_handler = true;
$result = $this->repository_engine->testRepositoryConnection();
if ($result === true) {
$save = $this->active_repository->save();
if ($save && !is_error($save)) {
db_commit();
flash_success(lang('Repository has been successfully updated'));
$this->redirectToUrl($this->active_repository->getHistoryUrl());
} else {
db_rollback();
$this->smarty->assign('errors', $save);
}
//if
} else {
db_rollback();
$errors = new ValidationErrors();
$errors->addError(lang('Failed to connect to repository: :message', array('message' => $result)));
$this->smarty->assign('errors', $errors);
}
// if
}
// if
js_assign('repository_test_connection_url', assemble_url('repository_test_connection', array('project_id' => $this->active_project->getId())));
$this->smarty->assign(array('types' => $this->active_repository->types, 'update_types' => $this->active_repository->update_types, 'repository_data' => $repository_data, 'active_repository' => $this->active_repository, 'disable_url_and_type' => instance_of($this->active_repository->getLastCommit(), 'Commit'), 'aid_url' => lang('The path to the existing repository cannot be changed'), 'aid_engine' => lang('Repository type cannot be changed')));
}
示例15: create_from_template
/**
* Creates a View for the given user, based off a given template and other
* View information supplied.
*
* Will set a default title of 'Copy of $viewtitle' if title is not
* specified in $viewdata.
*
* @param array $viewdata See View::_create
* @param int $templateid The ID of the View to copy
* @param int $userid The user who has issued the command to create the
* view. See View::_create
* @param int $checkaccess Whether to check that the user can see the view before copying it
* @return array A list consisting of the new view, the template view and
* information about the copy - i.e. how many blocks and
* artefacts were copied
* @throws SystemException under various circumstances, see the source for
* more information
*/
public static function create_from_template($viewdata, $templateid, $userid = null, $checkaccess = true)
{
if (is_null($userid)) {
global $USER;
$userid = $USER->get('id');
}
$user = new User();
$user->find_by_id($userid);
db_begin();
$template = new View($templateid);
if ($template->get('deleted')) {
throw new SystemException("View::create_from_template: This template has been deleted");
}
if (!$template->get('template') && !$user->can_edit_view($template)) {
throw new SystemException("View::create_from_template: Attempting to create a View from another View that is not marked as a template");
} else {
if ($checkaccess && !can_view_view($templateid, $userid)) {
throw new SystemException("View::create_from_template: User {$userid} is not permitted to copy View {$templateid}");
}
}
$view = self::_create($viewdata, $userid);
// Set a default title if one wasn't set
if (!isset($viewdata['title'])) {
$view->set('title', self::new_title(get_string('Copyof', 'mahara', $template->get('title')), (object) $viewdata));
$view->set('dirty', true);
}
try {
$copystatus = $view->copy_contents($template);
} catch (QuotaExceededException $e) {
db_rollback();
return array(null, $template, array('quotaexceeded' => true));
}
$view->commit();
db_commit();
return array($view, $template, $copystatus);
}