<commit_before><?php
class Sailthru_Email_ContentController extends Mage_Adminhtml_Controller_Action
{
    public function _isAllowed()
    {
        return Mage::getSingleton('admin/session')->isAllowed('sailthruemail/sailthru_content');
    }

    /**
     * <magento_uri>/content/bulk endpoint action
     */
    public function bulkAction() 
    {
        $data = $this->getRequest()->getPost();
        if ($data and array_key_exists('product', $data) and
            array_key_exists('massaction_prepare_key', $data) and $data['massaction_prepare_key'] == 'product' and
            array_key_exists('store', $data) and (int) $data['store'] > 0) {
            $this->_processItems($data['product'], $data['store']);
        } else {
            Mage::getSingleton('adminhtml/session')
                ->addError("Request to bulk update Sailthru was malformed. Please try again.");
        }

        $this->_redirectReferer();
    }

    /**
     * Send products to Sailthru by ID number and a given store
     * @param int[] $productIds
     * @param int $store
     */
    protected function _processItems($productIds, $store)
    {
        /** @var Mage_Core_Model_App_Emulation $appEmulation */
        $appEmulation = Mage::getSingleton('core/app_emulation');
        $emulateData = $appEmulation->startEnvironmentEmulation($store);
        $count = count($productIds);
        $startTime = microtime(true);

        $syncedProducts = 0;

        /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */
        $collection = Mage::getModel('catalog/product')
            ->getCollection();

        $collection
            ->addAttributeToSelect("*")
            ->addIdFilter($productIds)
            ->joinField('qty',
                'cataloginventory/stock_item',
                'qty',
                'product_id=entity_id',
                '{{table}}.stock_id=1',
                'left')
            ->setPageSize(75);

        $page = 1;
        do {
            $collection->setCurPage($page++)->load();

            /** @var Mage_Catalog_Model_Product $product */
            foreach ($collection->getItems() as $product) {
                try {
                    if ($product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
                        $success = Mage::getModel('sailthruemail/client_content')->saveProduct($product);
                        if ($success) {
                            $syncedProducts++;
                        }

                    } elseif ($product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) {<commit_msg>cleaning<commit_after><?php
class Sailthru_Email_ContentController extends Mage_Adminhtml_Controller_Action
{
    public function _isAllowed()
    {
        return Mage::getSingleton('admin/session')->isAllowed('sailthruemail/sailthru_content');
    }

    /**
     * <magento_uri>/content/bulk endpoint action
     */
    public function bulkAction() 
    {
        $data = $this->getRequest()->getPost();
        if ($data and array_key_exists('product', $data) and
            array_key_exists('massaction_prepare_key', $data) and $data['massaction_prepare_key'] == 'product' and
            array_key_exists('store', $data) and (int) $data['store'] > 0) {
            $this->_processItems($data['product'], $data['store']);
        } else {
            Mage::getSingleton('adminhtml/session')
                ->addError("Request to bulk update Sailthru was malformed. Please try again.");
        }

        $this->_redirectReferer();
    }

    /**
     * Send products to Sailthru by ID number and a given store
     * @param int[] $productIds
     * @param int $store
     */
    protected function _processItems($productIds, $store)
    {
        /** @var Mage_Core_Model_App_Emulation $appEmulation */
        $appEmulation = Mage::getSingleton('core/app_emulation');
        $emulateData = $appEmulation->startEnvironmentEmulation($store);
        $count = count($productIds);
        $startTime = microtime(true);

        $syncedProducts = 0;

        /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */
        $collection = Mage::getModel('catalog/product')
            ->getCollection();

        $collection
            ->addAttributeToSelect("*")
            ->addIdFilter($productIds)
            ->joinField('qty',
                'cataloginventory/stock_item',
                'qty',
                'product_id=entity_id',
                '{{table}}.stock_id=1',
                'left')
            ->setPageSize(75);

        $page = 1;
        do {
            $collection->setCurPage($page++)->load();

            /** @var Mage_Catalog_Model_Product $product */
            foreach ($collection->getItems() as $product) {
                try {
                    $status = $product->getStatus();
                    if ($status == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
                        $success = Mage::getModel('sailthruemail/client_content')->saveProduct($product);
                        if ($success) {
                            $syncedProducts++;
                        }

                    } elseif ($status == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) {
{'fraction_non_alphanumeric': 0.1302696543866312, 'fraction_numerical': 0.002278769464489176, 'mean_word_length': 2.1671677690920026, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 42, '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': '5325800', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1422, 'n_words': 250}