If condition inside Concrete5 Job not working - jobs

I don't even have a clue why this is happening. The if condition in my job is not working properly. I triple checked the $flag variable and it is true. Still the code always goes to the else condition.
$flag = file_exists($csvFile);
if($flag){
//A big chunk of code
} else {
return 'Whatever you do I will always go here XD';
}
I hard coded true inside if, it works properly. Then another if inside that chunk of code also always goes to else. Again double checked Express. Express object exists and object is returned properly. And is_object returns true.
$flag = file_exists($csvFile);
if(true){
//Some code here
$entity = Express::getObjectByHandle('user');
if(is_object($entity)){
// Another chunk of code
} else {
return 'You cant escape from me that easily... XD';
}
//some code here
} else {
return "Now I'm a good boy";
}
Tried a bunch of things. The code works without any problems in single page controllers. What ever I do it's just not working. I'm running PHP 5.6.10 on MAMP. Conceret5 8.1.0

The only time I've seen something like this is with a buggy older version of PHP.
You could try moving some code around like so:
if($flag = file_exists($csvFile)) {
// code to handle file
} else {
// no file
}
A followup post would help...

Well. Looks like I found the fix. It looks like a simple matter but don't know for sure. I was running the job from dashboard, I didn't knew I could run the same job from the url as well (Automate job option URL). It worked fine when I ran it from URL and Magically it started working inside the Dashboard as well. I will look into it in detail when I get the time.

Related

Kotlin use block function is not called on File.printWriter()

I'm new to Kotlin and I'm trying to do a simple task - create and write to a file. For some reason, using use() with a block function on printWriter() doesn't actually write.
File("test2.txt").printWriter().use { out ->
{
println("hmmm")
out.println("what's up")
log.info { "finished writing" }
}
}
In fact, the block function doesn't seem to be called at all - both "hmmm" and "finished writing" never show up, although the file itself is created (but is totally empty).
The much simpler writeText() works just fine - the file is created and the given text is written to the file.
File("test3.txt").writeText("testing")
What am I doing wrong in my use() version?
Edit: it seems to be a syntax issue with my block function. Looks like I have an extra pair of brackets? Would love a brief explanation as to why it makes it not work.
Edit 2: I think I understand now. The way I wrote it, I was essentially returning the block function itself rather than running through it.
So the problem was that the way I was writing the block function caused it to just return the inner block function, and not actually call it.
Here are two ways that work:
File("test2.txt").printWriter().use {
println("hmmm")
it.println("what's up")
log.info { "finished writing!" }
}
File("test2.txt").printWriter().use(fun(out) {
println("hmmm")
out.println("what's up")
log.info { "finished writing!" }
})
Although, for my purposes writeText() actually works just fine and is much shorter haha.

Getting type of SelectedShape in picture and content placeholder fails in VSTO

When running the following snippet of VSTO code I get a COM exception
if (param.SelectedShape.Type != MsoShapeType.msoPlaceholder) { //Stuff is happening }
The exception occurs when trying to read the Type property of SelectedShape.
We have been running with this code in PowerPoint (Office 365 ProPlus) for a long time, but somewhere between build 9126.2210 (works) and build 9330.2087 (doesn't work) it broke.
When looking through the release notes it doesn't seem like anything has been changed that should be related to this. What could have been changed?
You might try to use the call in a try/catch block like here:
try
{
if (param.SelectedShape.Type != MsoShapeType.msoPlaceholder)
{
// Stuff is happening
}
}
catch (COMException)
{
// Add logging here
}
This is a workaround. Of course, Microsoft should fix the problem.

Bypassing functions that do not exist

how would it be possible to bypass functions that are not existing in DM
such that the main code would still run? Try/catch does not seem to work, e..g
image doSomething(number a,number b)
{
try
{
whateverfunction(a,b)
}
catch
{
continue
}
}
number a,b
doSomething(a,b)
Also conditioning wont work, e.g..
image doSomething(number a,number b)
{
if(doesfunctionexist("whateverfunction"))
{
whateverfunction(a,b)
}
}
number a,b
doSomething(a,b)
thanks in advance!
As "unknown" commands are caught by the script-interpreter, there is no easy way to do this. However, you can construct a workaround by using ExecuteScriptCommand().
There is an example tutorial to be found in this e-book, but in short, you want to do something like the following:
String scriptCallStr = "beep();\n"
scriptCallStr = "MyUnsaveFunctionCall();\n"
number exitVal
Try { exitVal = ExecuteScriptString(scriptCallStr ); }
Catch { exitVal = -1; break; }
if ( -1 == exitVal )
{
OKDialog("Sorry, couldn't do:\n" + scriptCallStr )
}
else
{
OKDialog( "All worked. Exit value: " + exitVal )
}
This works nicely and easy for simple commands and if your task is only to "verify" that a script could run.
It becomes clumsy, when you need to pass around parameters. But even then there are ways to do so. (The 'outer' script could create an object and pass the object-ID per string. Similarly, the 'inner' script can do the same and return the script-object ID as exit-value.)
Note: You can of course also put doesfunctionexist inside the test-script, if you do only want to have a "safe test", but don't actually want to execute the command.
Depending on what you need there might also be another workaround solution: Wrapper-functions in a library. This can be useful if you want to run the same script on different PCs with some of which having the functionality - most likely some microscope - while others don't.
You can make your main-script use wrapper methods and then you install different versions of the wrapper method script scripts as libraries.
void My_SpecialFunction( )
{
SpecialFunction() // use this line on PCs which have the SpecialFunction()
DoNothing() // use alternative line on PCs which don't have the SpecialFunction()
}
My_SpecialFunction( )
I have used this in the past where the same functionality (-stage movement-) required different commands on different machines.

selenium webdriver sendkeys intermittent issue

I have a web automation framework set up that works pretty well. I have a constant issue though that when using SendKeys to write to textboxes, quite often a letter gets missed out. So for example, if my dataset is "TestUserName", something like "TestUerName" gets sent example with a missing letter.
This is a big issue for me, as after the web tests concludes successfully I further check if the database was updated properly. So in the above example I would go to the UserName column and expect to find TestUserName, but the test would fail because TestUerName is found instead.
Any ideas please? I am using selenium 2.53.0.
My code below.
public void inputValue (Object [][] valuesFromExcel)
{
for (int rowNow = 0; rowNow < (valuesFromExcel.length); rowNow++)
{
String newValue = valuesFromExcel[rowNow][0].toString();
if (!newValue.equals(""))
{
WebElement currentElement = driver.findElement(By.id(valuesFromExcel[rowNow][1].toString()));
if (currentElement.getTagName().equals("input"))
{
currentElement.sendKeys(newValue);
}
else if (currentElement.getTagName().equals("select"))
{
new Select(currentElement).selectByVisibleText(newValue);
}
}
}
}
Thanks.
Instead of sending as a string, send it as char...
Convert the string to char and send each char one by one to the text box. Yes there will be a performance issue, but it works fine. It will not skip any of the letters

Yii trace - proper usage

Unit testing and xdebug usage aside, I wish to have a way to throw some browser message is a value is not expected to be present.
Let's say: $className = 45;
If we have:
public function setMainClass($className) {
if (is_string($className)) {
$this->_mainClass = $className;
} else {
echo Yii::trace(CVarDumper::dumpAsString($className),'vardump');
}
}
We will get this output to the browser on development stage.
It's great.
I'm not sure however, if this is a proper way of use Yii::trace of if I'm miss using it.
Please advice.
It is not necessary to echo the call Yii::trace() (it returns void so the echo does nothing). The other recommendation is that you might consider changing category to resemble a path alias as discussed in the documentation. For example-
} else {
Yii::trace(CVarDumper::dumpAsString($className), 'application.models.MyGreatModel');
}