<commit_before><?php defined('SYSPATH') OR die('No direct script access.');

/**
 * Base model for assets and pages which provides functions for adding / removing tags.
 *
 * @package	BoomCMS
 * @category	Models
 * @author	<NAME>
 * @copyright	Hoop Associates
 *
 */
abstract class Boom_Model_Taggable extends ORM
{
	/**
	 * Adds a tag with a given path to the object.
	 *
	 * If the tag doesn't exist then [Model_Tag::create_from_path()] is called to create it.
	 *
	 *
	 * @param string $path
	 * @param integer $type
	 * @return \Boom_Model_Taggable
	 *
	 * @uses Model_Tag::create_from_path()
	 * @throws Exception
	 */
	public function add_tag_with_path($path, $type, array $ids = array())
	{
		// If the current page isn't loaded then we can't add a tag to it.
		if ( ! $this->_loaded)
		{
			// Throw an exception
			throw new Exception("Cannot add a tag to an unloaded page");
		}

		// Attempt to load a tag with the given path.
		$tag = ORM::factory('Tag', array('path' => $path, 'type' => $type));

		// If the tag wasn't found then call [Boom_Model_Tag::create_from_path()] to create it.
		if ( ! $tag->loaded())
		{
			// Create the tag.
			$tag = ORM::factory('Tag')->create_from_path($path, $type);
		}

		// Add the tag to the objects?
		try
		{<commit_msg>Bugfix: allow tags to be added to an unloaded taggable object when an array of IDs is given<commit_after><?php defined('SYSPATH') OR die('No direct script access.');

/**
 * Base model for assets and pages which provides functions for adding / removing tags.
 *
 * @package	BoomCMS
 * @category	Models
 * @author	<NAME>
 * @copyright	Hoop Associates
 *
 */
abstract class Boom_Model_Taggable extends ORM
{
	/**
	 * Adds a tag with a given path to the object.
	 *
	 * If the tag doesn't exist then [Model_Tag::create_from_path()] is called to create it.
	 *
	 *
	 * @param string $path
	 * @param integer $type
	 * @return \Boom_Model_Taggable
	 *
	 * @uses Model_Tag::create_from_path()
	 * @throws Exception
	 */
	public function add_tag_with_path($path, $type, array $ids = array())
	{
		// If the current page isn't loaded then we can't add a tag to it.
		if ( ! $this->_loaded AND empty($ids))
		{
			// Throw an exception
			throw new Exception("Cannot add a tag to an unloaded object");
		}

		// Attempt to load a tag with the given path.
		$tag = ORM::factory('Tag', array('path' => $path, 'type' => $type));

		// If the tag wasn't found then call [Boom_Model_Tag::create_from_path()] to create it.
		if ( ! $tag->loaded())
		{
			// Create the tag.
			$tag = ORM::factory('Tag')->create_from_path($path, $type);
		}

		// Add the tag to the objects?
		try
		{
{'fraction_non_alphanumeric': 0.13247539742619227, 'fraction_numerical': 0.0, 'mean_word_length': 3.3327868852459015, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '794602', 'n_tokens_mistral': 933, 'n_tokens_neox': 852, 'n_words': 309}