本文整理汇总了PHP中Model::deleteAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::deleteAll方法的具体用法?PHP Model::deleteAll怎么用?PHP Model::deleteAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::deleteAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteAllDuplicates
private function deleteAllDuplicates(Model $model, $duplicateKey)
{
if ($model->deleteAll(array($this->getDuplicateKey($model) => $duplicateKey, 'duplicate' => true))) {
return true;
}
return false;
}
示例2: gc
/**
* Helper function called on gc for database sessions.
*
* @param integer $expires
* Timestamp (defaults to current time)
* @return boolean Success
*/
public function gc($expires = null)
{
if (!$expires) {
$expires = time();
}
return $this->_model->deleteAll(array($this->_model->alias . ".expires <" => $expires), false, false);
}
示例3: afterDelete
/**
* afterFind Callback
* @param Model $Model
* @see cake/libs/model/ModelBehavior#afterDelete($model)
*/
function afterDelete(&$Model)
{
if ($this->__notAllow($Model)) {
return true;
}
$this->I18n->deleteAll(array('model' => $Model->name, 'foreign_key' => $Model->id));
}
示例4: uninstallPlugin
/**
* Uninstall plugin
*
* @param Model $model Model using this behavior
* @param array $data Plugin data
* @return bool True on success
* @throws InternalErrorException
*/
public function uninstallPlugin(Model $model, $data)
{
$model->loadModels(['Plugin' => 'PluginManager.Plugin', 'PluginsRole' => 'PluginManager.PluginsRole', 'PluginsRoom' => 'PluginManager.PluginsRoom']);
//トランザクションBegin
$model->setDataSource('master');
$dataSource = $model->getDataSource();
$dataSource->begin();
if (is_string($data)) {
$key = $data;
} else {
$key = $data[$model->alias]['key'];
}
try {
//Pluginの削除
if (!$model->deleteAll(array($model->alias . '.key' => $key), false)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
//PluginsRoomの削除
if (!$model->PluginsRoom->deleteAll(array($model->PluginsRoom->alias . '.plugin_key' => $key), false)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
//PluginsRoleの削除
if (!$model->PluginsRole->deleteAll(array($model->PluginsRole->alias . '.plugin_key' => $key), false)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
//トランザクションCommit
$dataSource->commit();
} catch (Exception $ex) {
//トランザクションRollback
$dataSource->rollback();
CakeLog::error($ex);
throw $ex;
}
return true;
}
示例5: deleteAll
function deleteAll($conditions, $params = array())
{
if (!empty($this->cache) and Base::getConfig('cache') >= 1 and Base::getConfig('cache_query') >= 1) {
$cache = Cache::getInstance($this->tablename . '.queries');
$cache->destroy();
}
return parent::deleteAll($conditions, $params);
}
示例6: gc
/**
* Helper function called on gc for database sessions.
*
* @param int $expires Timestamp (defaults to current time)
*
* @return bool Success
*/
public function gc($expires = NULL)
{
if (!$expires) {
$expires = time();
} else {
$expires = time() - $expires;
}
return $this->_model->deleteAll(array($this->_model->alias . ".expires <" => $expires), FALSE, FALSE);
}
示例7: setVersion
/**
* Set current version for given type
*
* @param integer $version Current version
* @param string $type Can be 'app' or a plugin name
* @param boolean $migrated If true, will add the record to the database
* If false, will remove the record from the database
* @return boolean
* @access public
*/
public function setVersion($version, $type, $migrated = true)
{
if ($migrated) {
$this->Version->create();
return $this->Version->save(array('version' => $version, 'type' => $type));
} else {
$conditions = array($this->Version->alias . '.version' => $version, $this->Version->alias . '.type' => $type);
return $this->Version->deleteAll($conditions);
}
}
示例8: deleteAll
function deleteAll($conditions, $cascade = true, $callbacks = false, $recursive = -1)
{
if (!isset($recursive)) {
$recursive = $this->recursive;
}
if ($recursive == -1) {
$this->unbindModel(array('belongsTo' => array_keys($this->belongsTo), 'hasOne' => array_keys($this->hasOne)), true);
}
return parent::deleteAll($conditions, $cascade, $callbacks);
}
示例9: deleteAll
/**
* Override deleteAll() to use softDeleteAll() from behavior
* Necessary as can't be done using callbacks
* @param array $conditions Search conditions to find records to delete
* @param boolean $cascade Whether to delete related records
* @param boolean $callbacks Whether to call callbacks
* @return boolean Whether the deletes were successful
*/
public function deleteAll($conditions, $cascade = true, $callbacks = false)
{
if (empty($conditions)) {
return false;
}
if ($this->Behaviors->hasMethod('softDeleteAll')) {
return $this->softDeleteAll($conditions, $cascade, $callbacks);
} else {
return parent::deleteAll($conditions, $cascade, $callbacks);
}
}
示例10: setVersion
/**
* Set current version for given type
*
* @param integer $version Current version
* @param string $type Can be 'app' or a plugin name
* @param boolean $migrated If true, will add the record to the database
* If false, will remove the record from the database
* @return boolean
*/
public function setVersion($version, $type, $migrated = true)
{
if ($type !== 'app') {
$type = Inflector::camelize($type);
}
$mapping = $this->getMapping($type);
// For BC, 002 was not applied yet.
$bc = $this->Version->schema('class') === null;
$field = $bc ? 'version' : 'class';
$value = $bc ? $version : $mapping[$version]['class'];
if ($migrated) {
$this->Version->create();
$result = $this->Version->save(array($field => $value, 'type' => $type));
} else {
$conditions = array($this->Version->alias . '.' . $field => $value, $this->Version->alias . '.type' => $type);
$result = $this->Version->deleteAll($conditions);
}
// Clear mapping cache
unset($this->__mapping[$type]);
return $result;
}
示例11: recover
/**
* Recover a corrupted tree
*
* The mode parameter is used to specify the source of info that is valid/correct. The opposite source of data
* will be populated based upon that source of info. E.g. if the MPTT fields are corrupt or empty, with the $mode
* 'parent' the values of the parent_id field will be used to populate the left and right fields. The missingParentAction
* parameter only applies to "parent" mode and determines what to do if the parent field contains an id that is not present.
*
* @todo Could be written to be faster, *maybe*. Ideally using a subquery and putting all the logic burden on the DB.
* @param Model $Model Model instance
* @param string $mode parent or tree
* @param mixed $missingParentAction 'return' to do nothing and return, 'delete' to
* delete, or the id of the parent to set as the parent_id
* @return boolean true on success, false on failure
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::recover
*/
public function recover($Model, $mode = 'parent', $missingParentAction = null)
{
if (is_array($mode)) {
extract(array_merge(array('mode' => 'parent'), $mode));
}
extract($this->settings[$Model->alias]);
$Model->recursive = $recursive;
if ($mode == 'parent') {
$Model->bindModel(array('belongsTo' => array('VerifyParent' => array('className' => $Model->name, 'foreignKey' => $parent, 'fields' => array($Model->primaryKey, $left, $right, $parent)))));
$missingParents = $Model->find('list', array('recursive' => 0, 'conditions' => array($scope, array('NOT' => array($Model->escapeField($parent) => null), $Model->VerifyParent->escapeField() => null))));
$Model->unbindModel(array('belongsTo' => array('VerifyParent')));
if ($missingParents) {
if ($missingParentAction == 'return') {
foreach ($missingParents as $id => $display) {
$this->errors[] = 'cannot find the parent for ' . $Model->alias . ' with id ' . $id . '(' . $display . ')';
}
return false;
} elseif ($missingParentAction == 'delete') {
$Model->deleteAll(array($Model->primaryKey => array_flip($missingParents)));
} else {
$Model->updateAll(array($parent => $missingParentAction), array($Model->escapeField($Model->primaryKey) => array_flip($missingParents)));
}
}
$count = 1;
foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey), 'order' => $left)) as $array) {
$lft = $count++;
$rght = $count++;
$Model->create(false);
$Model->id = $array[$Model->alias][$Model->primaryKey];
$Model->save(array($left => $lft, $right => $rght), array('callbacks' => false));
}
foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) {
$Model->create(false);
$Model->id = $array[$Model->alias][$Model->primaryKey];
$this->_setParent($Model, $array[$Model->alias][$parent]);
}
} else {
$db = ConnectionManager::getDataSource($Model->useDbConfig);
foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) {
$path = $this->getPath($Model, $array[$Model->alias][$Model->primaryKey]);
if ($path == null || count($path) < 2) {
$parentId = null;
} else {
$parentId = $path[count($path) - 2][$Model->alias][$Model->primaryKey];
}
$Model->updateAll(array($parent => $db->value($parentId, $parent)), array($Model->escapeField() => $array[$Model->alias][$Model->primaryKey]));
}
}
return true;
}
示例12: beforeDelete
/**
* beforeDelete
*
* @param Model $model
* @return void
* @access public
*/
function beforeDelete(&$model)
{
// プラグインコンテンツを自動削除する
$this->PluginContent->deleteAll(array('name' => $model->data[$model->alias]['name']));
}
示例13: deleteAll
/**
* Deletes multiple model records based on a set of conditions.
*
* @param mixed $conditions Conditions to match
* @param boolean $cascade Set to true to delete records that depend on this record
* @param boolean $callbacks Run callbacks (not being used)
* @return boolean True on success, false on failure
* @access public
* @link http://book.cakephp.org/view/692/deleteAll
*/
public function deleteAll($conditions, $cascade = true, $callbacks = false)
{
$result = parent::deleteAll($conditions, $cascade, $callbacks);
if ($result) {
if ($this->Behaviors->attached('BcCache') && $this->Behaviors->enabled('BcCache')) {
$this->delCache($this);
}
}
return $result;
}
示例14: send_mail
public function send_mail($locale, $status, $mailsendqueue, $mail_config, $mailsendname = '')
{
if (isset($status) && $status != 1) {
$this_model = new Model(false, 'mail_send_queues');
$this_model->deleteAll(array('flag' => '5'));
$mail_send_queue_info = $this_model->find('all', array('limit' => '10', 'order' => 'id asc'));
$this_model->saveAll($mailsendqueue);
return false;
} else {
$this->set_appconfigs($locale);
$this->smtpauth = isset($mail_config['mail-requires-authorization']) ? trim($mail_config['mail-requires-authorization']) : 1;
$this->is_ssl = trim($mail_config['mail-ssl']);
$this->is_mail_smtp = trim($mail_config['mail-service']);
$this->smtp_port = trim($mail_config['mail-port']);
$this->smtpHostNames = trim($mail_config['mail-smtp']);
$this->smtpUserName = trim($mail_config['mail-account']);
$this->smtpPassword = trim($mail_config['mail-password']);
$this->from = $mail_config['mail-address'];
$this_model = new Model(false, 'mail_send_histories');
$this->sendAs = $mailsendqueue['sendas'];
$this->fromName = $mailsendqueue['sender_name'];
$subject = $mailsendqueue['title'];
$this->subject = $mailsendqueue['title'];
//eval("\$subject = \"$subject\";");
//$this->subject="=?utf-8?B?".base64_encode($subject)."?=";
if (is_array($mailsendqueue['receiver_email'])) {
$to_email_and_name_arr = $mailsendqueue['receiver_email'];
$i = 0;
foreach ($to_email_and_name_arr as $k => $v) {
if (strpos($v, ';')) {
$to_email_and_name = explode(';', $v);
$to_name[$i] = $to_email_and_name[0];
$to_email[$i] = $to_email_and_name[1];
++$i;
}
}
} else {
$to_email_and_name = explode(';', $mailsendqueue['receiver_email']);
$to_name[] = $to_email_and_name[0];
$to_email[] = $to_email_and_name[1];
}
$mailsendqueue['receiver_email'] = json_encode($mailsendqueue['receiver_email']);
if (is_array($mailsendqueue['cc_email'])) {
$addcc_to_email_and_name_arr = $mailsendqueue['cc_email'];
$i = 0;
foreach ($addcc_to_email_and_name_arr as $k => $v) {
if (strpos($v, ';')) {
$addcc_to_email_and_name = explode(';', $v);
$addcc_to_name[$i] = $addcc_to_email_and_name[0];
//�ռ�������
$addcc_to_email[$i] = $addcc_to_email_and_name[1];
//�ռ���email
++$i;
}
}
} else {
if (trim($mailsendqueue['cc_email']) != '' && trim($mailsendqueue['cc_email']) != ';') {
$addcc_to_email_and_name = explode(';', $mailsendqueue['cc_email']);
if (trim($addcc_to_email_and_name[0]) != '' && trim($addcc_to_email_and_name[1]) != ';') {
$addcc_to_name[] = $addcc_to_email_and_name[0];
//�ռ�������
$addcc_to_email[] = $addcc_to_email_and_name[1];
//�ռ���email
}
}
}
$mailsendqueue['cc_email'] = json_encode($mailsendqueue['cc_email']);
if (is_array($mailsendqueue['bcc_email'])) {
$addbcc_to_email_and_name_arr = $mailsendqueue['bcc_email'];
$i = 0;
foreach ($addbcc_to_email_and_name_arr as $k => $v) {
if (strpos($v, ';')) {
$addbcc_to_email_and_name = explode(';', $v);
$addbcc_to_name[$i] = $addbcc_to_email_and_name[0];
//�ռ�������
$addbcc_to_email[$i] = $addbcc_to_email_and_name[1];
//�ռ���email
++$i;
}
}
} else {
if (trim($mailsendqueue['bcc_email']) != '' && trim($mailsendqueue['bcc_email']) != ';') {
$addbcc_to_email_and_name = explode(';', $mailsendqueue['bcc_email']);
if (trim($addbcc_to_email_and_name[0]) != '' && trim($addbcc_to_email_and_name[1]) != ';') {
$addbcc_to_name[] = $addbcc_to_email_and_name[0];
//�ռ�������
$addbcc_to_email[] = $addbcc_to_email_and_name[1];
//�ռ���email
}
}
}
$mailsendqueue['bcc_email'] = json_encode($mailsendqueue['bcc_email']);
$this->html_body = $mailsendqueue['html_body'];
$this->text_body = $mailsendqueue['text_body'];
for ($i = 0; $i < count($to_email); ++$i) {
$this->toName[$i] = trim($to_name[$i]);
$this->to[$i] = trim($to_email[$i]);
}
if (isset($addcc_to_name)) {
for ($i = 0; $i < count($addcc_to_name); ++$i) {
//.........这里部分代码省略.........
示例15: revertAll
/**
* Revert all rows matching conditions to given date.
* Model rows outside condition or not edited will not be affected. Edits since date
* will be reverted and rows created since date deleted.
*
* @param object $Model
* @param array $options 'conditions','date'
* @return boolean success
*/
public function revertAll(Model $Model, $options = array())
{
if (!$Model->ShadowModel) {
trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
return false;
}
if (empty($options) || !isset($options['date'])) {
return false;
}
if (!isset($options['conditions'])) {
$options['conditions'] = array();
}
// leave model rows out side of condtions alone
// leave model rows not edited since date alone
$all = $Model->find('all', array('conditions' => $options['conditions'], 'fields' => $Model->primaryKey));
$allIds = Set::extract($all, '/' . $Model->alias . '/' . $Model->primaryKey);
$cond = $options['conditions'];
$cond['version_created <'] = $options['date'];
$created_before_date = $Model->ShadowModel->find('all', array('order' => $Model->primaryKey, 'conditions' => $cond, 'fields' => array('version_id', $Model->primaryKey)));
$created_before_dateIds = Set::extract($created_before_date, '/' . $Model->alias . '/' . $Model->primaryKey);
$deleteIds = array_diff($allIds, $created_before_dateIds);
// delete all Model rows where there are only version_created later than date
$Model->deleteAll(array($Model->alias . '.' . $Model->primaryKey => $deleteIds), false, true);
unset($cond['version_created <']);
$cond['version_created >='] = $options['date'];
$created_after_date = $Model->ShadowModel->find('all', array('order' => $Model->primaryKey, 'conditions' => $cond, 'fields' => array('version_id', $Model->primaryKey)));
$created_after_dateIds = Set::extract($created_after_date, '/' . $Model->alias . '/' . $Model->primaryKey);
$updateIds = array_diff($created_after_dateIds, $deleteIds);
$revertSuccess = true;
// update model rows that have version_created earlier than date to latest before date
foreach ($updateIds as $mid) {
$Model->id = $mid;
if (!$Model->revertToDate($options['date'])) {
$revertSuccess = false;
}
}
return $revertSuccess;
}