<commit_before><?php

namespace Menu;

class Menu_Db extends Menu_Driver
{

	/**
	 * Root node id
	 * @var int
	 */
	protected $root;

	protected function _load()
	{
		$tree = Model_Menu::forge()->set_tree_id($this->id)->root()->get_one()->dump_tree();
		$tree = reset($tree);
		$this->root = \Arr::get($tree, 'id');
		return \Arr::get($tree, 'children', array());
	}

	protected function _update(array $menu, $root = null)
	{
		// No root passed, so get the tree root
		if (is_null($root))
		{
			$root = Model_Menu::forge()->find($this->root);
		}

		$previous = null;

		foreach ($menu as $id => $item)
		{
			$id = \Arr::get($item, 'id', $id);
			$model = Model_Menu::find($id);

			// Skip tree fields<commit_msg>Add menu item when does not exist<commit_after><?php

namespace Menu;

class Menu_Db extends Menu_Driver
{

	/**
	 * Root node id
	 * @var int
	 */
	protected $root;

	protected function _load()
	{
		$tree = Model_Menu::forge()->set_tree_id($this->id)->root()->get_one()->dump_tree();
		$tree = reset($tree);
		$this->root = \Arr::get($tree, 'id');
		return \Arr::get($tree, 'children', array());
	}

	protected function _update(array $menu, $root = null)
	{
		// No root passed, so get the tree root
		if (is_null($root))
		{
			$root = Model_Menu::forge()->find($this->root);
		}

		$previous = null;

		foreach ($menu as $item)
		{
			// Get id from input and find the model
			$id = \Arr::get($item, 'id');
			$model = Model_Menu::find($id);

			// If model is not found then forge it
			is_null($model) and $model = Model_Menu::forge();

			// Skip tree fields
{'fraction_non_alphanumeric': 0.1901452937460518, 'fraction_numerical': 0.0, 'mean_word_length': 3.5128205128205128, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3349946', 'n_tokens_mistral': 620, 'n_tokens_neox': 553, 'n_words': 147}