/** * @param $query string * @param $object Contextual_Mysqli */ public function onError($query, Contextual_Mysqli $object) { if (in_array($object->last_errno, [Errors::ER_ROW_IS_REFERENCED, Errors::ER_ROW_IS_REFERENCED_2]) && $object->context && is_string($object->context) && $object->isDelete($query)) { $id = $this->extractId($query); if ($id) { $controller_uri = SL . $object->context . SL . $id . SL . 'deleteAndReplace'; echo (new Main())->runController($controller_uri, [Parameter::AS_WIDGET => true]); } } }
/** * @param $object object * @param $property Reflection_Property * @param $map object[] */ private function writeMap($object, Reflection_Property $property, $map) { // old map $class = new Link_Class(get_class($object)); $composite_property_name = $class->getAnnotation('link')->value ? $class->getCompositeProperty()->name : null; $old_object = Search_Object::create(Link_Class::linkedClassNameOf($object)); $this->setObjectIdentifier($old_object, $this->getObjectIdentifier($object, $composite_property_name)); $aop_getter_ignore = Getter::$ignore; Getter::$ignore = false; $old_map = $property->getValue($old_object); Getter::$ignore = $aop_getter_ignore; // map properties : write each of them $insert_builder = new Map_Insert($property); $id_set = []; foreach ($map as $element) { $id = $this->getObjectIdentifier($element) ?: $this->getObjectIdentifier($this->write($element)); if (!isset($old_map[$id])) { $query = $insert_builder->buildQuery($object, $element); $this->connection->query($query); } else { $id_set[$id] = true; } } // remove old unused elements $delete_builder = new Map_Delete($property); foreach ($old_map as $old_element) { $id = $this->getObjectIdentifier($old_element); if (!isset($id_set[$id])) { $query = $delete_builder->buildQuery($object, $old_element); $this->connection->query($query); } } }
/** * @param $mysqli Contextual_Mysqli * @param $query string * @return boolean true if the query with an error can be retried after this error was dealt with */ private function onCantCreateTableError(Contextual_Mysqli $mysqli, $query) { $retry = false; $error_table_names = $this->parseNamesFromQuery($query); foreach ($error_table_names as $error_table_name) { if (!$mysqli->exists($error_table_name)) { $this->createImplicitTable($mysqli, $error_table_name, ['id']); } $retry = true; } return $retry; }