本文整理汇总了PHP中AuditEvent::deleteAllByModel方法的典型用法代码示例。如果您正苦于以下问题:PHP AuditEvent::deleteAllByModel方法的具体用法?PHP AuditEvent::deleteAllByModel怎么用?PHP AuditEvent::deleteAllByModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuditEvent
的用法示例。
在下文中一共展示了AuditEvent::deleteAllByModel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: autoBuildModels
//.........这里部分代码省略.........
* inconsistencies do not matter for the purpose of auto building the database, and are
* semantic information that is not available and not needed for this process. The idea is
* to create as few models as possible.
*
* Call this an empty unfrozen database with all the models required for certain tests, or
* all the models required for the production database. Then freeze the database.
*
* If a model references a non-leaf model in the hierarchy an example of a model subclassed
* from that type must be included in the $modelClassNames. eg: 'Opportunity' references
* Permitable via its permissions and an abstract 'Permitable' cannot be created, so 'User'
* needs be created at the same time since it is concrete and can be used to create an
* Opportunity.
* ie: $modelClassNames = array('Opportunity', 'User').
*/
public static function autoBuildModels(array $modelClassNames, &$messageLogger)
{
assert('AssertUtil::all($modelClassNames, "is_string")');
assert('$messageLogger instanceof MessageLogger');
if (!self::isAutoBuildStateValid()) {
self::deleteAllSampleModelsFromStatePersisterAndDatabase($messageLogger);
}
self::setAutoBuildStateInStatePersister(self::AUTO_BUILD_STATE_INVALID);
AuditEvent::$isTableOptimized = false;
self::$modelClassNamesToSampleModels = array();
foreach ($modelClassNames as $modelClassName) {
$messages[] = array('info' => "Auto building {$modelClassName}.");
self::autoBuildSampleModel($modelClassName, $modelClassNames, $messageLogger);
$messageLogger->addInfoMessage("Auto build of {$modelClassName} done.");
}
foreach (self::$modelClassNamesToSampleModels as $modelClassName => $model) {
if (!$model instanceof OwnedModel && !$model instanceof OwnedCustomField && !$model instanceof OwnedMultipleValuesCustomField) {
try {
$model->setScenario('autoBuildDatabase');
$saved = $model->save();
if ($saved) {
self::setSampleModelInStatePersister(get_class($model), $model->id);
$metadata = $model->getMetadata();
foreach ($metadata as $unused => $classMetadata) {
if (!empty($classMetadata['relations'])) {
foreach ($classMetadata['relations'] as $relationName => $relationTypeModelClassNameAndOwns) {
$relationType = $relationTypeModelClassNameAndOwns[0];
$relatedModelClassName = $relationTypeModelClassNameAndOwns[1];
$owned = isset($relationTypeModelClassNameAndOwns[2]) && $relationTypeModelClassNameAndOwns[2] == RedBeanModel::OWNED;
if (get_class($model) == get_class($model->{$relationName}) && $model->id == $model->{$relationName}->id) {
$messageLogger->addInfoMessage("Unset {$modelClassName}->{$relationName} to avoid recursion and thread stack overrun.");
$model->{$relationName} = null;
$model->save();
}
}
}
}
} else {
$messageLogger->addErrorMessage("*** Saving the sample {$modelClassName} failed.");
$errors = $model->getErrors();
if (count($errors) > 0) {
$messageLogger->addErrorMessage('The attributes that did not validate probably need more rules, or are not deletable types.');
$messageLogger->addErrorMessage(print_r($errors, true));
} else {
$messageLogger->addErrorMessage('No attributes failed to validate!');
}
}
$messageLogger->addInfoMessage("Auto built {$modelClassName} saved.");
} catch (NotSupportedException $e) {
$messageLogger->addErrorMessage("*** Saving the sample {$modelClassName} failed.");
if (is_subclass_of($modelClassName, 'OwnedCustomField') || is_subclass_of($modelClassName, 'OwnedMultipleValuesCustomField') || is_subclass_of($modelClassName, 'OwnedModel')) {
$messageLogger->addErrorMessage('It is OWNED and was probably not saved via its owner, making it not a root model.');
} else {
$messageLogger->addErrorMessage('The save failed but there were no validation errors.');
}
}
}
}
foreach (self::$modelClassNamesToSampleModels as $modelClassName => $model) {
try {
if (!$model->isDeleted()) {
if (!$model->delete()) {
if ($model->id < 0) {
$messageLogger->addInfoMessage(get_class($model) . " Not Deleted but never saved so this is ok. (Most likely it is a - Has Many Owned)");
} else {
$messageLogger->addErrorMessage("*** Deleting the sample " . get_class($model) . " failed. It would not delete.");
}
} else {
$messageLogger->addInfoMessage(get_class($model) . " Deleted (Not Owned).");
}
} else {
$messageLogger->addInfoMessage(get_class($model) . " Deleted Already (Owned).");
}
AuditEvent::deleteAllByModel($model);
unset(self::$modelClassNamesToSampleModels[$modelClassName]);
} catch (NotSupportedException $e) {
$messageLogger->addErrorMessage("*** Deleting the sample {$modelClassName} failed. It is marked not deletable.");
}
}
if (count(self::$modelClassNamesToSampleModels)) {
$messageLogger->addErrorMessage('*** Deleting of the sample(s) ' . join(', ', array_keys(self::$modelClassNamesToSampleModels)) . " didn't happen.");
}
AuditEvent::$isTableOptimized = false;
self::deleteAllSampleModelsFromStatePersister();
self::setAutoBuildStateInStatePersister(self::AUTO_BUILD_STATE_VALID);
}