<commit_before><?php
/**
 * @version      $Id$
 * @category	 Nooku
 * @package      Nooku_Server
 * @subpackage   Articles
 * @copyright    Copyright (C) 2011 Timble CVBA and Contributors. (http://www.timble.net).
 * @license      GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link         http://www.nooku.org
 */

/**
 * Cascadable Database Behavior Class
 *
 * @author      <NAME> <http://nooku.assembla.com/profile/johnbell>
 * @category	Nooku
 * @package     Nooku_Server
 * @subpackage  Articles    
 */
class ComArticlesDatabaseBehaviorCascadable extends KDatabaseBehaviorAbstract
{
    /**
     * List of dependent columns
     * 
     * @var array
     */
    protected $_dependents;
    
	/**
	 * Constructor.
	 *
	 * $config->dependents array An array of identifiers of the dependent tables 
	 * in the format: com://app/package.model.name.column where column contains the 'foreign key'
	 *
	 * @param 	object 	An optional KConfig object with configuration options
	 */
	public function __construct( KConfig $config = null) 
	{ 
	    parent::__construct($config);
	    
	    $this->_dependents = $config->dependents;
	} 

	/**
     * Initializes the options for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param 	object 	An optional KConfig object with configuration options
     * @return void
     */
	protected function _initialize(KConfig $config)
    {
    	$config->append(array(
			'dependents' => array('com://admin/categories.model.categories.parent'),
	  	));

    	parent::_initialize($config);
   	}
    
    /**
     * Deletes dependent rows.
     *
     * This performs an intelligent delete 
     *
     * @return KDatabaseRowAbstract
     */
    protected function _beforeTableDelete(KCommandContext $context)
    {
        $result = true;
        
        $id = $this->get($this->getTable()->getIdentityColumn());
        
        foreach($this->_dependents as $dependent)
        {                 
            $parts  = explode('.', $dependent);
            $column = array_pop($parts);
            $name   = array_pop($parts);
            
            $identifier = implode('.', $parts).'.'.$name;
            
            $rowset = KFactory::get($identifier)
                        ->set($column, $id)
                        ->limit(0)
                        ->getList();

            if($rowset->count()) {
                $result = $rowset->delete();
            } 
        }
        
        return $result;       
    }
}<commit_msg>Synced with changes in framework. Use KObject->getService() instead of KFactory::get().<commit_after><?php
/**
 * @version      $Id$
 * @category	 Nooku
 * @package      Nooku_Server
 * @subpackage   Articles
 * @copyright    Copyright (C) 2011 Timble CVBA and Contributors. (http://www.timble.net).
 * @license      GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link         http://www.nooku.org
 */

/**
 * Cascadable Database Behavior Class
 *
 * @author      <NAME> <http://nooku.assembla.com/profile/johnbell>
 * @category	Nooku
 * @package     Nooku_Server
 * @subpackage  Articles    
 */
class ComArticlesDatabaseBehaviorCascadable extends KDatabaseBehaviorAbstract
{
    /**
     * List of dependent columns
     * 
     * @var array
     */
    protected $_dependents;
    
	/**
	 * Constructor.
	 *
	 * $config->dependents array An array of identifiers of the dependent tables 
	 * in the format: com://app/package.model.name.column where column contains the 'foreign key'
	 *
	 * @param 	object 	An optional KConfig object with configuration options
	 */
	public function __construct( KConfig $config = null) 
	{ 
	    parent::__construct($config);
	    
	    $this->_dependents = $config->dependents;
	} 

	/**
     * Initializes the options for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param 	object 	An optional KConfig object with configuration options
     * @return void
     */
	protected function _initialize(KConfig $config)
    {
    	$config->append(array(
			'dependents' => array('com://admin/categories.model.categories.parent'),
	  	));

    	parent::_initialize($config);
   	}
    
    /**
     * Deletes dependent rows.
     *
     * This performs an intelligent delete 
     *
     * @return KDatabaseRowAbstract
     */
    protected function _beforeTableDelete(KCommandContext $context)
    {
        $result = true;
        
        $id = $this->get($this->getTable()->getIdentityColumn());
        
        foreach($this->_dependents as $dependent)
        {                 
            $parts  = explode('.', $dependent);
            $column = array_pop($parts);
            $name   = array_pop($parts);
            
            $identifier = implode('.', $parts).'.'.$name;
            
            $rowset = $this->getService($identifier)
                        ->set($column, $id)
                        ->limit(0)
                        ->getList();

            if($rowset->count()) {
                $result = $rowset->delete();
            } 
        }
        
        return $result;       
    }
}
{'fraction_non_alphanumeric': 0.12417921977597528, 'fraction_numerical': 0.002317497103128621, 'mean_word_length': 2.004060324825986, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '7592559', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1452, 'n_words': 341}