X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Third Party Add-Ons for X-Cart 5 (https://forum.x-cart.com/forumdisplay.php?f=64)
-   -   Module - Database Field Problem with Null (https://forum.x-cart.com/showthread.php?t=74847)

GlasPak 01-06-2017 07:45 AM

Module - Database Field Problem with Null
 
I have had a module for a while that I wrote that creates a "Products Per Case" ppcField field in xcProducts .. For some reason everytime I update the site (or disable a module) it attempts to reset this field to Not Null (this field can be null and default is set to Null). How do I prevent Xcart redeploy (step 5 I believe) to stop trying to set this field to Not Null?

Here is the error in the php_error log

Code:

[06-Jan-2017 15:33:21] Error (code: 0): An exception occurred while executing 'ALTER TABLE xc_products CHANGE PPCField PPCField VARCHAR(32) NOT NULL':

SQLSTATE[22004]: Null value not allowed: 1138 Invalid use of NULL value
Server API: fpm-fcgi;
Request method: GET;
URI: /admin.php?target=addons_list_installed&__cache_key__=82b5339fc4a155b03641a06c2c6b47ad&cpid=34d5b4bb4d90caf09248f04d54627d4c;
Backtrace:
#0 /home/numus/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(116): Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))
#1 /home/numus/public_html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(836): Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Object(XLite\Core\PDOMySqlDriver), Object(Doctrine\DBAL\Driver\PDOException), 'ALTER TABLE xc_...', Array)
#2 /home/numus/public_html/var/run.82b5339fc4a155b03641a06c2c6b47ad/classes/XLite/Core/Connection.php(51): Doctrine\DBAL\Connection->executeQuery('ALTER TABLE xc_...', Array, Array, NULL)
#3 /home/numus/public_html/var/run.82b5339fc4a155b03641a06c2c6b47ad/classes/XLite/Core/DatabaseAbstract.php(657): XLite\Core\Connection->executeQuery('ALTER TABLE xc_...')
#4 /home/numus/public_html/Includes/Decorator/Plugin/Doctrine/Plugin/UpdateSchema/Main.php(28): XLite\Core\DatabaseAbstract->executeQueries(Array)
#5 /home/numus/public_html/Includes/Decorator/Utils/PluginManager.php(62): Includes\Decorator\Plugin\Doctrine\Plugin\UpdateSchema\Main->executeHookHandler()
#6 /home/numus/public_html/Includes/Decorator/Utils/CacheManager.php(981): Includes\Decorator\Utils\PluginManager::invokeHook('step_fifth')
#7 [internal function]: Includes\Decorator\Utils\CacheManager::executeStepHandler5()
#8 /home/numus/public_html/Includes/Utils/Operator.php(213): call_user_func_array(Array, Array)
#9 /home/numus/public_html/Includes/Decorator/Utils/CacheManager.php(826): Includes\Utils\Operator::executeWithCustomMaxExecTime('600', Array)
#10 /home/numus/public_html/Includes/Decorator/Utils/CacheManager.php(845): Includes\Decorator\Utils\CacheManager::runStep(5)
#11 /home/numus/public_html/Includes/Decorator/Utils/CacheManager.php(1188): Includes\Decorator\Utils\CacheManager::runStepConditionally(5)
#12 /home/numus/public_html/top.inc.PHP53.php(90): Includes\Decorator\Utils\CacheManager::rebuildCache()
#13 /home/numus/public_html/top.inc.php(26): require_once('/home/numus/pub...')
#14 /home/numus/public_html/admin.php(16): require_once('/home/numus/pub...')
#15 {main}


qualiteam 01-08-2017 10:31 PM

Re: Module - Database Field Problem with Null
 
How does your Model class (the one that adds the field) look like?

GlasPak 01-09-2017 06:32 AM

Re: Module - Database Field Problem with Null
 
Quote:

Originally Posted by qualiteam
How does your Model class (the one that adds the field) look like?


Code:

<?php
// vim: set ts=4 sw=4 sts=4 et:

namespace XLite\Module\EBLIEB\GlasPak\Model;

class Product extends \XLite\Model\Product implements \XLite\Base\IDecorator
{
    /**
    * @Column (type="string", length=32)
    */
    protected $PPCField;
   
    /**
    * Updates "Pieces per case" field.
    *
    * @param string $value New value
    *
    * @return void
    */
    public function setPPCField($value)
    {
        $this->PPCField = $value;
    }

    /**
    * Returns the value of "Pieces per case" field.
    *
    * @return string
    */
    public function getPPCField()
    {
        return $this->PPCField;
    }
}


http://devs.x-cart.com/en/basics/understanding_models.html - This doesn't seem to reference Not Null vs Null...

Edit:

Does Xlite follow the doctrine? http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html

Would this work to my PPCField set to null?

Code:

{
    /**
    * @Column (type="string", length=32, nullable=true)
    */
    protected $PPCField;


qualiteam 01-10-2017 11:57 PM

Re: Module - Database Field Problem with Null
 
Quote:

Would this work to my PPCField set to null?
Code:

@Column (type="string", length=32, nullable=true)


Yes, this should work.

Also, if you need the opposite, you can it like this:
Code:

@Column (type="integer", options={ "unsigned": true, "default": 0 })


All times are GMT -8. The time now is 03:31 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.