/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $_SESSION['dblog_overview_filter'] = array(); $this->connection->delete('watchdog')->execute(); drupal_set_message($this->t('Database log cleared.')); $form_state->setRedirectUrl($this->getCancelUrl()); }
/** * @param DrupalStyle $io * @param $eventType * @param $eventSeverity * @param $userId * @return bool */ protected function clearEvents(DrupalStyle $io, $eventType, $eventSeverity, $userId) { $severity = RfcLogLevel::getLevels(); $query = $this->database->delete('watchdog'); if ($eventType) { $query->condition('type', $eventType); } if ($eventSeverity) { if (!in_array($eventSeverity, $severity)) { $io->error(sprintf($this->trans('commands.database.log.clear.messages.invalid-severity'), $eventSeverity)); return false; } $query->condition('severity', array_search($eventSeverity, $severity)); } if ($userId) { $query->condition('uid', $userId); } $result = $query->execute(); if (!$result) { $io->error($this->trans('commands.database.log.clear.messages.clear-error')); return false; } $io->success($this->trans('commands.database.log.clear.messages.clear-sucess')); return true; }
/** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { $_SESSION['dblog_overview_filter'] = array(); $this->connection->delete('watchdog')->execute(); drupal_set_message($this->t('Database log cleared.')); $form_state['redirect_route'] = $this->getCancelRoute(); }
/** * {@inheritdoc} */ public function delete($conditions) { $path = $this->load($conditions); $query = $this->connection->delete('url_alias'); foreach ($conditions as $field => $value) { $query->condition($field, $value); } $deleted = $query->execute(); // @todo Switch to using an event for this instead of a hook. $this->moduleHandler->invokeAll('path_delete', array($path)); return $deleted; }
/** * {@inheritdoc} */ public function delete($module = NULL, $uid = NULL, $name = NULL) { $query = $this->connection->delete('users_data'); // Cast scalars to array so we can consistently use an IN condition. if (isset($module)) { $query->condition('module', (array) $module, 'IN'); } if (isset($uid)) { $query->condition('uid', (array) $uid, 'IN'); } if (isset($name)) { $query->condition('name', (array) $name, 'IN'); } $query->execute(); }
/** * {@inheritdoc} */ protected function doDelete($entities) { $ids = array_keys($entities); $this->database->delete($this->entityType->getBaseTable())->condition($this->idKey, $ids, 'IN')->execute(); // Reset the cache as soon as the changes have been applied. $this->resetCache($ids); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $uid = $input->getArgument('uid'); $account = User::load($uid); if (!$account) { // Error loading User entity. $io->error(sprintf($this->trans('commands.user.login.clear.attempts.errors.invalid-user'), $uid)); return 1; } // Define event name and identifier. $event = 'user.failed_login_user'; // Identifier is created by uid and IP address, // Then we defined a generic identifier. $identifier = "{$account->id()}-"; // Retrieve current database connection. $schema = $this->database->schema(); $flood = $schema->findTables('flood'); if (!$flood) { $io->error($this->trans('commands.user.login.clear.attempts.errors.no-flood')); return 1; } // Clear login attempts. $this->database->delete('flood')->condition('event', $event)->condition('identifier', $this->database->escapeLike($identifier) . '%', 'LIKE')->execute(); // Command executed successful. $io->success(sprintf($this->trans('commands.user.login.clear.attempts.messages.successful'), $uid)); }
/** * {@inheritdoc} */ public function delete($uid) { // Nothing to do if we are not allowed to change the session. if (!$this->writeSafeHandler->isSessionWritable() || $this->isCli()) { return; } $this->connection->delete('sessions')->condition('uid', $uid)->execute(); }
/** * Creates delete query. * * @param string $table * The table name. * @param array $keys * Array with object keys indexed by field name. * * @return \Drupal\Core\Database\Query\Delete * Returns a new Delete object for the injected database connection. */ protected function dbDelete($table, $keys) { $query = $this->connection->delete($table, $this->options); foreach ($keys as $field => $value) { $query->condition($field, $value); } return $query; }
/** * {@inheritdoc} */ public function garbageCollection() { try { $return = $this->connection->delete(static::TABLE_NAME)->condition('expiration', REQUEST_TIME, '<')->execute(); } catch (\Exception $e) { $this->catchException($e); } }
/** * {@inheritdoc} */ public function cleanup() { try { // Cleanup the batch table and the queue for failed batches. $this->connection->delete('batch')->condition('timestamp', REQUEST_TIME - 864000, '<')->execute(); } catch (\Exception $e) { $this->catchException($e); } }
/** * Responds to entity DELETE requests. * * @param int $id * The ID of the record. * * @return \Drupal\rest\ModifiedResourceResponse * The HTTP response object. * * @throws \Symfony\Component\HttpKernel\Exception\HttpException */ public function delete($id) { // Make sure the record still exists. $this->loadRecord($id); $this->dbConnection->delete('example_foo')->condition('id', $id)->execute(); $this->logger->notice('Deleted record with ID %id.'); // Deleted responses have an empty body. return new ModifiedResourceResponse(NULL, 204); }
/** * {@inheritdoc} */ public function deleteAll($prefix = '') { try { $options = array('return' => Database::RETURN_AFFECTED) + $this->options; return (bool) $this->connection->delete($this->table, $options)->condition('name', $prefix . '%', 'LIKE')->condition('collection', $this->collection)->execute(); } catch (\Exception $e) { return FALSE; } }
/** * Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection(). */ public function garbageCollection() { try { $this->connection->delete($this->bin)->condition('expire', Cache::PERMANENT, '<>')->condition('expire', REQUEST_TIME, '<')->execute(); } catch (\Exception $e) { // If the table does not exist, it surely does not have garbage in it. // If the table exists, the next garbage collection will clean up. // There is nothing to do. } }
/** * {@inheritdoc} */ public function gc($lifetime) { // Be sure to adjust 'php_value session.gc_maxlifetime' to a large enough // value. For example, if you want user sessions to stay in your database // for three weeks before deleting them, you need to set gc_maxlifetime // to '1814400'. At that value, only after a user doesn't log in after // three weeks (1814400 seconds) will his/her session be removed. $this->connection->delete('sessions')->condition('timestamp', REQUEST_TIME - $lifetime, '<')->execute(); return TRUE; }
/** * {@inheritdoc} */ public function releaseAll($lock_id = NULL) { // Only attempt to release locks if any were acquired. if (!empty($this->locks)) { $this->locks = array(); if (empty($lock_id)) { $lock_id = $this->getLockId(); } $this->database->delete('semaphore')->condition('value', $lock_id)->execute(); } }
/** * {@inheritdoc} */ public function garbageCollection() { try { // Clean up the queue for failed batches. $this->connection->delete(static::TABLE_NAME)->condition('created', REQUEST_TIME - 864000, '<')->condition('name', 'drupal_batch:%', 'LIKE')->execute(); // Reset expired items in the default queue implementation table. If that's // not used, this will simply be a no-op. $this->connection->update(static::TABLE_NAME)->fields(array('expire' => 0))->condition('expire', 0, '<>')->condition('expire', REQUEST_TIME, '<')->execute(); } catch (\Exception $e) { $this->catchException($e); } }
/** * Implements Drupal\file\FileUsage\FileUsageInterface::delete(). */ public function delete(FileInterface $file, $module, $type = NULL, $id = NULL, $count = 1) { // Delete rows that have a exact or less value to prevent empty rows. $query = $this->connection->delete($this->tableName)->condition('module', $module)->condition('fid', $file->id()); if ($type && $id) { $query->condition('type', $type)->condition('id', $id); } if ($count) { $query->condition('count', $count, '<='); } $result = $query->execute(); // If the row has more than the specified count decrement it by that number. if (!$result && $count > 0) { $query = $this->connection->update($this->tableName)->condition('module', $module)->condition('fid', $file->id()); if ($type && $id) { $query->condition('type', $type)->condition('id', $id); } $query->expression('count', 'count - :count', array(':count' => $count)); $query->execute(); } parent::delete($file, $module, $type, $id, $count); }
/** * {@inheritdoc} */ public function delete(array $ids = NULL, ServerInterface $server = NULL, $index = NULL) { $delete = $this->database->delete('search_api_task'); if ($ids) { $delete->condition('id', $ids, 'IN'); } if ($server) { $delete->condition('server_id', $server->id()); } if ($index) { $delete->condition('index_id', $index instanceof IndexInterface ? $index->id() : $index); } $delete->execute(); }
/** * Dumps a set of routes to the router table in the database. * * Available options: * - provider: The route grouping that is being dumped. All existing * routes with this provider will be deleted on dump. * - base_class: The base class name. * * @param array $options * An array of options. */ public function dump(array $options = array()) { // Convert all of the routes into database records. // Accumulate the menu masks on top of any we found before. $masks = array_flip($this->state->get('routing.menu_masks.' . $this->tableName, array())); // Delete any old records first, then insert the new ones. That avoids // stale data. The transaction makes it atomic to avoid unstable router // states due to random failures. $transaction = $this->connection->startTransaction(); try { // We don't use truncate, because it is not guaranteed to be transaction // safe. try { $this->connection->delete($this->tableName)->execute(); } catch (\Exception $e) { $this->ensureTableExists(); } // Split the routes into chunks to avoid big INSERT queries. $route_chunks = array_chunk($this->routes->all(), 50, TRUE); foreach ($route_chunks as $routes) { $insert = $this->connection->insert($this->tableName)->fields(array('name', 'fit', 'path', 'pattern_outline', 'number_parts', 'route')); $names = array(); foreach ($routes as $name => $route) { /** @var \Symfony\Component\Routing\Route $route */ $route->setOption('compiler_class', '\\Drupal\\Core\\Routing\\RouteCompiler'); /** @var \Drupal\Core\Routing\CompiledRoute $compiled */ $compiled = $route->compile(); // The fit value is a binary number which has 1 at every fixed path // position and 0 where there is a wildcard. We keep track of all such // patterns that exist so that we can minimize the number of path // patterns we need to check in the RouteProvider. $masks[$compiled->getFit()] = 1; $names[] = $name; $values = array('name' => $name, 'fit' => $compiled->getFit(), 'path' => $route->getPath(), 'pattern_outline' => $compiled->getPatternOutline(), 'number_parts' => $compiled->getNumParts(), 'route' => serialize($route)); $insert->values($values); } // Insert all new routes. $insert->execute(); } } catch (\Exception $e) { $transaction->rollback(); watchdog_exception('Routing', $e); throw $e; } // Sort the masks so they are in order of descending fit. $masks = array_keys($masks); rsort($masks); $this->state->set('routing.menu_masks.' . $this->tableName, $masks); $this->routes = NULL; }
/** * {@inheritdoc} */ public function deleteMails(array $conditions) { // Continue to support 'nid'. if (!empty($conditions['nid'])) { $conditions['entity_type'] = 'node'; $conditions['entity_id'] = $conditions['nid']; unset($conditions['nid']); } $query = $this->connection->delete('simplenews_mail_spool'); foreach ($conditions as $condition => $value) { $query->condition($condition, $value); } return $query->execute(); }
/** * Implements \Drupal\user\UserDataInterface::delete(). */ public function delete($module = NULL, $uid = NULL, $name = NULL) { $query = $this->connection->delete('users_data'); if (isset($module)) { $query->condition('module', $module); } if (isset($uid)) { $query->condition('uid', $uid); } if (isset($name)) { $query->condition('name', $name); } $query->execute(); }
/** * {@inheritdoc} */ public function deleteItems(IndexInterface $index, array $item_ids) { try { if (empty($this->configuration['field_tables'][$index->id()])) { return; } foreach ($this->configuration['field_tables'][$index->id()] as $field) { $this->database->delete($field['table'])->condition('item_id', $item_ids, 'IN')->execute(); } // Delete the denormalized field data. $this->database->delete($this->configuration['index_tables'][$index->id()])->condition('item_id', $item_ids, 'IN')->execute(); } catch (\Exception $e) { throw new SearchApiException($e->getMessage(), $e->getCode(), $e); } }
/** * Deletes all of a flag's count entries. * * @param \Drupal\flag\event\FlagResetEvent $event * The flag reset event. */ public function resetFlagCounts(FlagResetEvent $event) { /* @var \Drupal\flag\FlaggingInterface flag */ $flag = $event->getFlag(); $this->connection->delete('flag_counts') ->condition('flag_id', $flag->id()) ->execute(); // Reset statically cached counts. $this->entityCounts = []; $this->flagCounts = []; $this->flagEntityCounts = []; $this->userFlagCounts = []; }
/** * {@inheritdoc} */ public function deleteFromBook($nid) { $original = $this->loadBookLink($nid, FALSE); $this->connection->delete('book')->condition('nid', $nid)->execute(); if ($nid == $original['bid']) { // Handle deletion of a top-level post. $result = $this->connection->query("SELECT * FROM {book} WHERE pid = :nid", array(':nid' => $nid))->fetchAllAssoc('nid', \PDO::FETCH_ASSOC); foreach ($result as $child) { $child['bid'] = $child['nid']; $this->updateOutline($child); } } $this->updateOriginalParent($original); $this->books = NULL; \Drupal::cache('data')->deleteTags(array('bid' => $original['bid'])); }
/** * Delete a phonebook entry. * * @param \Drupal\Core\Routing\RouteMatch $routeMatch */ public function delete(RouteMatch $routeMatch) { // CSRF is already checked by the routing system, so we're only making sure // that an existing item is being deleted. $pbid = $routeMatch->getParameter('phonebook'); $query = $this->connection->select('phonebook', 'p')->fields('p', ['name']); $query->condition('pbid', $pbid); $entry = $query->execute()->fetchObject(); if (!$entry) { // Return a 404 if the entry is not found. throw new NotFoundHttpException(); } $this->connection->delete('phonebook')->condition('pbid', $pbid)->execute(); drupal_set_message($this->t('Deleted entry for %name.', ['%name' => $entry->name])); return new RedirectResponse('/phonebook'); }
/** * {@inheritdoc} */ public function deleteItems(IndexInterface $index, array $item_ids) { try { $db_info = $this->getIndexDbInfo($index); if (empty($db_info['field_tables'])) { return; } foreach ($db_info['field_tables'] as $field) { $this->database->delete($field['table'])->condition('item_id', $item_ids, 'IN')->execute(); } // Delete the denormalized field data. $this->database->delete($db_info['index_table'])->condition('item_id', $item_ids, 'IN')->execute(); } catch (\Exception $e) { // The database operations might throw PDO or other exceptions, so we // catch them all and re-wrap them appropriately. throw new SearchApiException($e->getMessage(), $e->getCode(), $e); } }
/** * {@inheritdoc} */ public function delete($conditions) { $path = $this->load($conditions); $query = $this->connection->delete('url_alias'); foreach ($conditions as $field => $value) { if ($field == 'source' || $field == 'alias') { // Use LIKE for case-insensitive matching. $query->condition($field, $this->connection->escapeLike($value), 'LIKE'); } else { $query->condition($field, $value); } } $deleted = $query->execute(); // @todo Switch to using an event for this instead of a hook. $this->moduleHandler->invokeAll('path_delete', array($path)); Cache::invalidateTags(['route_match']); return $deleted; }
/** * {@inheritdoc} */ public function delete($id) { // Children get re-attached to the menu link's parent. $item = $this->loadFull($id); // It's possible the link is already deleted. if ($item) { $parent = $item['parent']; $children = $this->loadByProperties(array('parent' => $id)); foreach ($children as $child) { $child['parent'] = $parent; $this->save($child); } $this->connection->delete($this->table, $this->options)->condition('id', $id)->execute(); $this->updateParentalStatus($item); // Many children may have moved. $this->resetDefinitions(); Cache::invalidateTags(array('menu:' . $item['menu_name'])); } }
/** * {@inheritdoc} */ public function deleteNodeRecords(array $nids) { $this->database->delete('node_access')->condition('nid', $nids, 'IN')->execute(); }