<commit_before><?php
/**
 * NovaeZSEOBundle Legacy Type
 *
 * @package   Novactive\Bundle\eZSEOBundle
 * @author    Novactive <<EMAIL>>
 * @copyright 2015 Novactive
 * @license   https://github.com/Novactive/NovaeZSEOBundle/blob/master/LICENSE MIT Licence
 */

use Novactive\Bundle\eZSEOBundle\Core\FieldType\Metas\Type;
use Novactive\Bundle\eZSEOBundle\Core\Meta;
use Novactive\Bundle\eZSEOBundle\Core\FieldType\Metas\Value as FieldValue;

/**
 * Class NovaSeoMetasType
 */
class NovaSeoMetasType extends eZDataType
{

    const TABLE = "novaseo_meta";

    const STORAGE_FIELD = "data_text1";

    /**
     * Constructor
     */
    function __construct()
    {
        parent::__construct(
            Type::IDENTIFIER,
            ezpI18n::tr( 'extension/novaseo/text', "Nova SEO Metas", 'Datatype name' )
        );
    }

    /**
     * Validate post data, these are then used by
     * {@link NovaSeoMetasType::fetchObjectAttributeHTTPInput()}
     *
     * @param eZHTTPTool               $http
     * @param string                   $base
     * @param eZContentObjectAttribute $contentObjectAttribute
     *
     * @return eZInputValidator
     */
    function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
        if ( $http->hasPostVariable(
            "{$base}_data_novaseometas_{$contentObjectAttribute->attribute(
                'contentclass_attribute_identifier'
            )}_keyvalue_{$contentObjectAttribute->attribute( 'id' )}"
        ) )
        {
            $metasKv = $http->postVariable(
                "{$base}_data_novaseometas_{$contentObjectAttribute->attribute(
                    'contentclass_attribute_identifier'
                )}_keyvalue_{$contentObjectAttribute->attribute( 'id' )}"
            );
            //@todo: Maybe check some errors here
            unset( $metasKv );
            //$contentObjectAttribute->setValidationError( $mess );
            //$contentObjectAttribute->setHasValidationError();
            //return eZInputValidator::STATE_INVALID;
        }

        return eZInputValidator::STATE_ACCEPTED;
    }

    /**
     * Set parameters from post data, expects post data to be validated by
     * {@link eZNovaSeoMetasType::validateObjectAttributeHTTPInput()}
     *
     * @param eZHTTPTool               $http
     * @param string                   $base
     * @param eZContentObjectAttribute $contentObjectAttribute
     *
     * @return boolean
     */
    function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
        $metas = [];
        if ( $http->hasPostVariable( 'PublishButton' ) )
        {
            if ( $http->hasPostVariable(
                "{$base}_data_novaseometas_{$contentObjectAttribute->attribute(
                    'contentclass_attribute_identifier'
                )}_keyvalue_{$contentObjectAttribute->attribute( 'id' )}"
            ) )
            {
                $metasKv = $http->postVariable(
                    "{$base}_data_novaseometas_{$contentObjectAttribute->attribute(
                        'contentclass_attribute_identifier'
                    )}_keyvalue_{$contentObjectAttribute->attribute( 'id' )}"
                );
                foreach ( $metasKv as $metaKey => $metaValue )
                {
                    $meta = new Meta();
                    $meta->setName( $metaKey );
                    $meta->setContent( $metaValue );
                    $metas[] = $meta;
                }
            }
        }<commit_msg>Fix #11. fetchObjectAttributeHTTPInput all the time<commit_after><?php
/**
 * NovaeZSEOBundle Legacy Type
 *
 * @package   Novactive\Bundle\eZSEOBundle
 * @author    Novactive <<EMAIL>>
 * @copyright 2015 Novactive
 * @license   https://github.com/Novactive/NovaeZSEOBundle/blob/master/LICENSE MIT Licence
 */

use Novactive\Bundle\eZSEOBundle\Core\FieldType\Metas\Type;
use Novactive\Bundle\eZSEOBundle\Core\Meta;
use Novactive\Bundle\eZSEOBundle\Core\FieldType\Metas\Value as FieldValue;

/**
 * Class NovaSeoMetasType
 */
class NovaSeoMetasType extends eZDataType
{

    const TABLE = "novaseo_meta";

    const STORAGE_FIELD = "data_text1";

    /**
     * Constructor
     */
    function __construct()
    {
        parent::__construct(
            Type::IDENTIFIER,
            ezpI18n::tr( 'extension/novaseo/text', "Nova SEO Metas", 'Datatype name' )
        );
    }

    /**
     * Validate post data, these are then used by
     * {@link NovaSeoMetasType::fetchObjectAttributeHTTPInput()}
     *
     * @param eZHTTPTool               $http
     * @param string                   $base
     * @param eZContentObjectAttribute $contentObjectAttribute
     *
     * @return eZInputValidator
     */
    function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
        if ( $http->hasPostVariable(
            "{$base}_data_novaseometas_{$contentObjectAttribute->attribute(
                'contentclass_attribute_identifier'
            )}_keyvalue_{$contentObjectAttribute->attribute( 'id' )}"
        ) )
        {
            $metasKv = $http->postVariable(
                "{$base}_data_novaseometas_{$contentObjectAttribute->attribute(
                    'contentclass_attribute_identifier'
                )}_keyvalue_{$contentObjectAttribute->attribute( 'id' )}"
            );
            //@todo: Maybe check some errors here
            unset( $metasKv );
            //$contentObjectAttribute->setValidationError( $mess );
            //$contentObjectAttribute->setHasValidationError();
            //return eZInputValidator::STATE_INVALID;
        }

        return eZInputValidator::STATE_ACCEPTED;
    }

    /**
     * Set parameters from post data, expects post data to be validated by
     * {@link eZNovaSeoMetasType::validateObjectAttributeHTTPInput()}
     *
     * @param eZHTTPTool               $http
     * @param string                   $base
     * @param eZContentObjectAttribute $contentObjectAttribute
     *
     * @return boolean
     */
    function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
        $metas = [];
        if ( $http->hasPostVariable(
            "{$base}_data_novaseometas_{$contentObjectAttribute->attribute(
                'contentclass_attribute_identifier'
            )}_keyvalue_{$contentObjectAttribute->attribute( 'id' )}"
        ) )
        {
            $metasKv = $http->postVariable(
                "{$base}_data_novaseometas_{$contentObjectAttribute->attribute(
                    'contentclass_attribute_identifier'
                )}_keyvalue_{$contentObjectAttribute->attribute( 'id' )}"
            );
            foreach ( $metasKv as $metaKey => $metaValue )
            {
                $meta = new Meta();
                $meta->setName( $metaKey );
                $meta->setContent( $metaValue );
                $metas[] = $meta;
            }
        }
{'fraction_non_alphanumeric': 0.10921944885297936, 'fraction_numerical': 0.002308469196364161, 'mean_word_length': 2.1338155515370705, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 42, 'https://': 2, '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': '6000702', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1900, 'n_words': 324}