DMXzone Server Connect Support Product Page

Solved

When I put in a condition, "Else" appears first and then "Then". And it's not working when I test

Reported 05 Nov 2018 15:14:10
1
has this problem
05 Nov 2018 15:14:10 Bruce Wilkie posted:
Hi there

I'm trying to update a database table for a news item with a thumbnail. No problem inserting, but when I build in server connect and put in the condition to say if there is a thumbnail then crops it, resize it and update the record, the structure changes round so that 'Else' is above 'Then'.

prntscr.com/lenb5v

Hoped that it wouldn't matter, but when I test it doesn't work as intended. I'm not sure if this is because I've made a mistake or if it's a problem with the software.

Please help

Bruce

Replies

Replied 05 Nov 2018 15:18:03
05 Nov 2018 15:18:03 Teodor Kuduschiev replied:
Hello,
It doesn't matter if ELSE is first or THEN. They execute properly depending on where you put the code to execute (in ELSE or in THEN).
Replied 05 Nov 2018 15:29:25
05 Nov 2018 15:29:25 Bruce Wilkie replied:
OK, thanks Teodor. I'll keep trying
Replied 05 Nov 2018 15:51:08
05 Nov 2018 15:51:08 Bruce Wilkie replied:
Hi Teodor

Have started a new server action and, accepting that it always starts with 'Else' and then has 'Then' after it, I'm still having problems with the update.

I've simplified it to see if I can get it to work. Basically, I'm doing the following steps:

Condition: if there's a thumbnail
- Upload file (and ignore it from this point in this simplified test)
- Database Connection
- update database (ignoring the file/image in the update for now)
Else:
- Database Connection
- update database (but not the file/image as there isn't one)

As it stands, if I select an image for the thumbnail and submit the form, then the update works. But if I don't select an image for the thumbnail then the update doesn't work.

Any ideas what's causing the problem?

prntscr.com/lenr92

Else: (doesn't update)
prntscr.com/lenrpa
prntscr.com/lenrzs

Then: (updates fine)
prntscr.com/lensau
prntscr.com/lensn4

Bruce
Replied 05 Nov 2018 16:22:01
05 Nov 2018 16:22:01 Bruce Wilkie replied:
Hi again

Tried it another way, creating a new server action as follows:

prntscr.com/leo5va

Note, I've had to put a "select" into the 'else' option as it won't let me leave that blank. All the select does is select the news_id from the database table and then ignores it.

Still only updates the record if I've selected a thumbnail image. Again, it's set up to not actually update the thumbnail field in the record.

I can't figure out what the problem is. It seems it will only execute an update if I've selected an image for the thumbnail.

Hope you can help. I've been 6 hours today just trying to upload a thumbnail and then update a record.
Replied 05 Nov 2018 16:25:28
05 Nov 2018 16:25:28 Bruce Wilkie replied:
I can pay you if you like. Honestly I don't mind, just so long as we get this to work. Please
Replied 06 Nov 2018 08:18:25
06 Nov 2018 08:18:25 Teodor Kuduschiev replied:
Hello Bruce,
It's not about any payment you should make. This is one of the easiest and most used tasks so it shouldn't be causing any issue...

I see a couple of things that can be improved in your action file.
1. You don't need a database connection step in each condition. Put the database connection step as a first step in your action file.
2. You don't need an image load step after the upload step - just upload and update step after it.

Please fix these and check for any errors as explained here: www.dmxzone.com/go/32354/debugging-problems-in-dmxzone-server-connect/
Replied 06 Nov 2018 09:59:24
06 Nov 2018 09:59:24 Bruce Wilkie replied:
Hi Teodor

I've put the database connection at the top, but still need to load the image to get the size and width in order to crop it to a square before resizing down.

Have tested again and it's still only updating the database if there's an image selected in the file field of the form.

prntscr.com/leyamw

prntscr.com/leyc6t

Can you have a look at it if I give you access to the server and or my laptop?

Bruce
Replied 06 Nov 2018 11:36:21
06 Nov 2018 11:36:21 Teodor Kuduschiev replied:
Well in every post you show some different server action structure ... now your screenshot shows different steps than the last two posts.
What exactly are you trying to do? I am not sure i understand this...
Replied 06 Nov 2018 12:06:00
06 Nov 2018 12:06:00 Bruce Wilkie replied:
I've tried to simplify it as much as possible to make it easier to spot what's causing the problem.

This is what it's supposed to do when the form is filled out and the submit button clicked:

check if there's a file selected in the file field of the form.
If no file selected, just update the database record with the info in the other fields of the form and ignore the file field
If a file is selected then upload the file, crop it to a square image, resize to 320 square and then update the database record with the info in the form, including the file

Can I give you access to the server so you can look over the files and see why it's not working?

Replied 06 Nov 2018 12:08:31
06 Nov 2018 12:08:31 Bruce Wilkie replied:
Code from what I think must be the server connect action for this:

<?php
require('../../../dmxConnectLib/dmxConnect.php');


$app = new \lib\App();

$app->define(<<<'JSON'
{
"meta": {
"options": {
"linkedFile": "/adminarea/test-01.htm",
"linkedForm": "serverconnectform1"
},
"$_POST": [
{
"type": "text",
"fieldName": "news_title",
"name": "news_title"
},
{
"type": "file",
"fieldName": "news_thumbnail",
"name": "news_thumbnail",
"sub": [
{
"name": "name",
"type": "text"
},
{
"name": "type",
"type": "text"
},
{
"name": "size",
"type": "number"
},
{
"name": "error",
"type": "text"
}
],
"outputType": "file"
},
{
"type": "text",
"fieldName": "news_date",
"name": "news_date"
},
{
"type": "text",
"fieldName": "news_id",
"name": "news_id"
},
{
"type": "text",
"fieldName": "news_teaser",
"name": "news_teaser"
},
{
"type": "text",
"fieldName": "news_content",
"name": "news_content"
}
]
},
"exec": {
"steps": [
"Connections/connection1",
{
"name": "",
"module": "core",
"action": "condition",
"options": {
"if": "{{$_POST.news_thumbnail}}",
"then": {
"steps": [
{
"name": "upload1",
"module": "upload",
"action": "upload",
"options": {
"fields": "{{$_POST.news_thumbnail}}",
"path": "/images/news-pics"
},
"meta": [
{
"name": "name",
"type": "text"
},
{
"name": "path",
"type": "text"
},
{
"name": "url",
"type": "text"
},
{
"name": "type",
"type": "text"
},
{
"name": "size",
"type": "text"
},
{
"name": "error",
"type": "number"
}
],
"outputType": "file"
},
{
"name": "image1",
"module": "image",
"action": "load",
"options": {
"path": "{{upload1.path}}"
},
"outputType": "object",
"meta": [
{
"name": "width",
"type": "number"
},
{
"name": "height",
"type": "number"
}
]
},
{
"name": "",
"module": "core",
"action": "condition",
"options": {
"if": "{{image1.width}} > {{image1.height}}",
"then": {
"steps": {
"name": "",
"module": "image",
"action": "crop",
"options": {
"instance": "image1",
"x": "center",
"y": "middle",
"width": "{{image1.height}}",
"height": "{{image1.height}}"
}
}
},
"else": {
"steps": {
"name": "",
"module": "image",
"action": "crop",
"options": {
"instance": "image1",
"x": "center",
"y": "middle",
"width": "{{image1.width}}",
"height": "{{image1.width}}"
}
}
}
}
},
{
"name": "",
"module": "image",
"action": "resize",
"options": {
"instance": "image1",
"width": 320,
"height": 320
}
},
{
"name": "newImage1",
"module": "image",
"action": "save",
"options": {
"instance": "image1",
"quality": 80,
"overwrite": true,
"path": "/images/news-pics"
}
}
]
},
"else": {
"steps": {
"name": "query1",
"module": "dbconnector",
"action": "select",
"options": {
"connection": "connection1",
"sql": {
"type": "select",
"table": "news",
"columns": [
{
"table": "news",
"column": "news_id",
"value": "{{$_POST.news_id}}",
"type": "number"
}
],
"wheres": [],
"orders": [],
"joins": []
}
},
"output": true,
"meta": [
{
"name": "news_id",
"type": "text"
}
],
"outputType": "array"
}
}
}
},
{
"name": "update1",
"module": "dbupdater",
"action": "update",
"options": {
"connection": "connection1",
"sql": {
"type": "update",
"table": "news",
"values": [
{
"table": "news",
"column": "news_date",
"value": "{{$_POST.news_date}}",
"type": "date"
},
{
"table": "news",
"column": "news_title",
"value": "{{$_POST.news_title}}",
"type": "text"
},
{
"table": "news",
"column": "news_teaser",
"value": "{{$_POST.news_teaser}}",
"type": "text"
},
{
"table": "news",
"column": "news_content",
"value": "{{$_POST.news_content}}",
"type": "text"
}
],
"wheres": [
{
"table": "news",
"column": "news_id",
"bool": "and",
"operator": "=",
"value": "{{$_POST.news_id}}",
"type": "number"
}
]
}
},
"meta": [
{
"name": "affected",
"type": "number"
}
]
}
]
}
}
JSON
);
?>
Replied 06 Nov 2018 12:17:25
06 Nov 2018 12:17:25 Teodor Kuduschiev replied:
Check if your condition is properly set up.
It must check the "name" returned by the POST variable, not just the POST variable: prntscr.com/lf04wo
Replied 06 Nov 2018 12:22:09
06 Nov 2018 12:22:09 Bruce Wilkie replied:
What are data bindings? I don't recognise that window. Where do I find it?
Replied 06 Nov 2018 12:23:05
06 Nov 2018 12:23:05 Teodor Kuduschiev replied:
Bruce, this is the dynamic data picker for your condition value...
Replied 06 Nov 2018 12:24:08
06 Nov 2018 12:24:08 Bruce Wilkie replied:
These are the two conditions in there:

prntscr.com/lf07ui

prntscr.com/lf085p

Are they right?
Replied 06 Nov 2018 12:26:07
06 Nov 2018 12:26:07 Teodor Kuduschiev replied:
Did you check my previous reply?


QuoteCheck if your condition is properly set up.
It must check the "name" returned by the POST variable, not just the POST variable: prntscr.com/lf04wo

Replied 06 Nov 2018 12:26:28
06 Nov 2018 12:26:28 Bruce Wilkie replied:
Ah, ok. I see now. Trying with the name now.

Bruce
Replied 06 Nov 2018 12:38:22
06 Nov 2018 12:38:22 Bruce Wilkie replied:
OK, that seems to have fixed the problem with it not updating the record now. Thanks for that Teodor

There's just one last thing that's causing an issue now. It seems that when I moved the insert action to the end, after the file has been uploaded, cropped, resized and saved again; I can't now select that file to be inserted into the record. I can only select post variables: prntscr.com/lf0c08

Previously I used the image that had been uploaded as per instructions in video. How can I get it back into the selection options for updating the record again?

What I can see:
prntscr.com/lf0c08

From the DMX video:
prntscr.com/lf0f4h

Bruce
Replied 06 Nov 2018 12:40:44
06 Nov 2018 12:40:44 Teodor Kuduschiev replied:
That is because of the condition steps, as we don't know what your condition will return - then/else and we cannot display the output. Just type this manually.
Replied 06 Nov 2018 12:50:02
06 Nov 2018 12:50:02 Bruce Wilkie replied:
OK, typed in {{upload1.name}} and all working fine now.

Thanks so much for your help Teodor. Really appreciate it

Bruce

Reply to this topic