Editor 2.2.2 Upload failing when including additional fields

Editor 2.2.2 Upload failing when including additional fields

James12345James12345 Posts: 14Questions: 5Answers: 0

PHP

    ->upload( Upload::inst( savePath.'__NAME__')//.__EXTN__' )
        ->db( 'files', 'id', array(
            'filename'    => Upload::DB_FILE_NAME,
            'filesize'    => Upload::DB_FILE_SIZE,
            'web_path'    => Upload::DB_FILE_NAME, //Upload::DB_WEB_PATH,
            'system_path' => Upload::DB_SYSTEM_PATH,
            'extension' => Upload::DB_EXTN,
            'createdate' => date("Y-m-d H:i:s") ,
            'modifiydate' => date("Y-m-d H:i:s")    
        ) )

editor 2.0.10
Upload.php
line 649

    default:
        if ( is_callable($prop) && is_object($prop) ) { // is a closure
            $q->set( $column, $prop( $db, $upload ) );
        }
        else {
            $q->set( $column, $prop );
        }

        break;

editor 2.2.22
Line 662

default:
    $val = $prop;

    // Callable function - execute to get the value
    if (is_callable($prop) && is_object($prop)) {
        $val = $prop($db, $upload);
    }

    // If the primary key value was set - use that
    if ($column === $this->_dbPKey) {
        $insertedId = $val;
    }

    if (is_string($val) && !empty($val)) {
        // Allow for replacement of __ID__, etc when the value is a string
        $pathFields[$column] = $val;
        $q->set($column, '-'); // Use a temporary value (as above)
    } else {
        $q->set($column, $val);
    }

    break;

Web debug:
The fields "createdate" and "modifiydate" values are set to "-"

Error:
After updating to Editor 2.2.2 and trying to upload a file I started receiving the following error:

"An SQL error occurred: SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Conversion failed when converting data and/or time from character string."

Checking the web response the two date fields I specified "createdate" and "modifydate" values were both set to hyphen "-"

After investigating the error it appears to be caused in the Upload.php code section as shown above.

I have reverted the "default" section of code in Upload.php to the Editor 2.0.10 version (as above) and it is working again. The Editor reference states that you can add additional fields to the array. I am unsure how to resolve the issue.

The same issue occurs on using PHP 8.1.23 and 8.1.24

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Thanks for posting this - I can see how that would a problem. It needs a valid data to be set. This part of the code is proving to be surprisingly awkward to get right - sometimes a default is needed, sometimes not, and if it is needed it has to be of a certain type. I'm going to have to expose a more verbose way of setting that value I think.

    Good to hear you have a workaround for now.

    Allan

  • Mairie du PecqMairie du Pecq Posts: 14Questions: 4Answers: 0
    edited July 24

    EDIT : sorry, read too fast. I will do like James for the default part.

    Hi, i have the same problem than James12345. When i update editor 2.0.10 to 2.2.2 i receive the "An SQL error occurred: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value:"

    ->db( 'decisions_fichiers', 'id', array(
                        'filename'    => Upload::DB_FILE_NAME,
                        'filesize'    => Upload::DB_FILE_SIZE,
                        'web_path'    => Upload::DB_WEB_PATH,
                        'system_path' => Upload::DB_SYSTEM_PATH,
                        'nom'     => $_SESSION['nom'],
                        'prenom'  => $_SESSION['prenom'],
                        'date'    => date("Y-m-d"),
                        'heure'   => date("H:i:s")
                    ) )
    
Sign In or Register to comment.