How to send email automatically in Yii2? - yii2

How to send email automatically?
My current scenario is I want to trigger mail sending automatically after 15 days.

First step would be to create a command line that can be called to send the mail.
Yii2 supports commands. I would recommend you to make a simple command like this (place in /command app dir). You will need to update config/console.php if using db etc
namespace app\commands;
use yii\console\Controller;
class mailController extends Controller {
public function actionSend() {
//code here to send the mail
}
}
The code sample to send mail can be obtained here
Now you can run this command from shell / command prompt in the yii root dir as below
yii mail/send
Next step is to run this command every 15 days.
Running scheduled jobs require you to have an external trigger on your set interval.
On unix systems, this trigger is provided by cron jobs , an example here
You can configure the cron job as below
0 0 1,16 * * /path/to/yiiroot/yii mail/send

Related

Solved - SSIS - Send mail on error task sends multiple mails

I build a SSIS-Package to import data from an excel-file. As the excel file is required to have a certain scheme, it fails sometimes if the person creating the file does not stick to the scheme. For this case, i want to send a mail to this person, informing about the fail. I tried different methods but the send mail task always sends 5 to 6 mails instead of one.
The basic structure of my package is this:
The mail task is a simple "Send Mail Task" via SMTP Connection Manager and without attachements, only a message.
Previous approaches are:
With the Event Handler: Settings i tried are Event Handler: OnError and Executable: Whole Package level, on the foreach loop container and on the single "Import File" Task, as this is the one that fails.
In the control flow: I conneted the mail task on failure with the loop container and also with the single import file task:
I also played with the "Delay Validation"-setting in the properties, setting it on true for the loop container and also the import file task.
Where is the mistake i make and how can i fix the package to send only one mail instead of 5-6? Thanks in advance!
Update: The Problem kinda solved itself. I changed from a send mail task to a script task to send a mail with a logfile, this worked perfectly. I also changed the mail_from in the send mail task from a mail-container to a single mail, and this also solved the problem. After that, i changed again to the mail-container and it also works how it should. Seems to be a bug. Thanks all.

Where to place custom code for early initialization of DB session in Laravel?

I need to run custom SQL commands to initialize the DB session for my Laravel app.
The code must be invoked by the framework after Laravel has set up everything (i.e. configuration, DB connection, logging, etc.), but before an actual HTTP request or CLI request is served. Note, the solution must also work, for a CLI command via ./artisan <something>.
In case anybody wonders what code I want to run, here it is
$connection = Schema::connection(null)->getConnection();
if ($connection->getDriverName() == 'mysql') {
$sql_mode = DB::selectOne('SELECT ##SESSION.sql_mode AS sql_mode');
DB::statement('SET SESSION sql_mode=\'' . $sql_mode->sql_mode . ',NO_AUTO_VALUE_ON_ZERO\'');
}
Where should I add this code to ensure it's run at the needed time?

Iron Python get triggered in initial load for Spotfire Client but not for Spotfire Web player

My script is to hide some pages for the some login User. My script get trigger well in Client not in Webplayer.
To trigger this script i created the Data function property with Input and output parameter.
Input parameter as sysdate
output assigned to document property where below script is present.
import Spotfire.Dxp
from Spotfire.Dxp.Data import *
table=Document.Data.Tables["RestrictedSSO"]
minCol=table.Columns['GROUPNAME']
minCursor=DataValueCursor.Create(minCol)
for row in table.GetRows(minCursor):
Document.Properties["UserGroup"]= minCursor.CurrentValue;
if Document.Properties["UserGroup"]=="Restricted":
for Page in Document.Pages:
if Page.Title == "ABCD":
Document.Pages.Remove(Page)
if Page.Title == "EFGH":
Document.Pages.Remove(Page)
First check if there is a URL specified for the TERR Engine. A default setting might work in the client and not in the webplayer, so specifying the URL can ensure it works in both Client and Webplayer.
If that still does not help you can choose to initiate the python script via Javascript instead of the TERR sysdate output : https://community.tibco.com/wiki/how-trigger-python-script-report-load-javascript-tibco-spotfire
When using TERR Check whether you have have checked refresh automatically and unchecked allow cache from script in data function.
Run terr on server rather than run locally.
Go to file-> Document properties -> uncheck Remember personalized view for each web client user.
Even after doing the above steps if it didn't worked , then you can also go with java script.

MySQL listen notify equivalent

Is there an equivalent of PostgresQL's notify and listen in MySQL? Basically, I need to listen to triggers in my Java application server.
Ok, so what I found is that you can make UDF functions in mysql that can do anything but need to be written in C/C++. They can be then called from triggers on updates in database and notify your application when update happened. I saw that there are some security concerns. I did not use it myself but from what I can see it looks like something that could accomplish what you want to do and more.
http://dev.mysql.com/doc/refman/5.6/en/adding-udf.html
The github project mysql-notification provides a MySQL user defined function MySQLNotification() as a plugin to MySQL that will send notification events via a socket interface. This project includes a sample NodeJS test server that receives the notification events that could be adapted for Java or any other socket service.
Example use:
$ DELIMITER ##
$ CREATE TRIGGER <triggerName> AFTER INSERT ON <table>
FOR EACH ROW
BEGIN
SELECT MySQLNotification(NEW.id, 2) INTO #x;
END##
Project includes full source code and installation instructions for OSX and Linux. License is GNU v3.
No, there aren't any built-in functions like these yet.
You need to "ping" (every 1-5 seconds) database with selecting with premade flag like "read" 0/1. After
SELECT * FROM mytable WHERE read = 0
update it with read = 1
I needed to do this, so I designed my application to send the update notices itself.
E.g.
--Scenario--
User A is looking at record 1
User B saves an update to record 1 while User A has it open.
Process:
I wrote my own socket server as a Windows Service. I designed a que like system which is basically,
EntityType EntityID NoticeType
Where the EntityType is the type of Poco in my data layer that needs to send out notices, EntityID is the primary key value of the row that changed in sql (the values of the poco), and NoticeType is 1 Updated, 2 Inserted, and 3 Deleted.
The socket server accepts connections from the server side application code on a secure connection "meaning client side code cannot make requests designed to be sent by the server side application code"
The socket server accepts a message like
900 1 1023 1
Which would mean the server needs to notify concerned client connections that Entity Type 1 "Person" with ID 1023 was Updated.
The server knows what users need to be notified because when User's look at a record, they are registered in the socket server as having an interest in the record and the record's ID which is done by the web socket code in the client side javascript.
Record 1 is a POCO in my app code that has an IsNew and IsDirty field. "Using EntityFrameWork6 and MySql" If UserB's save caused an actual change (and not just saving existing data) IsDirty will be true on the postback on UserB's POCO.
The application code see's the record is dirty then notifies the socket server with a server side sent socket "which will be allowed" that says Entity 1 with ID 1023 was Updated.
The socket server sees it, and puts it in the que.
Being .Net, I have a class for concerned users that uses the same pocos from the data layer running in the Socket Server window service. I use linq to select users who are working with an entity matching the entity type and primary key id of the entity in the que.
It then loops through those users and sends them a socket like
901 1 1023 1 letting them know the entity was updated.
The javascript in the client side receives it causing users B's page to do an ajax postback on Record 1, But what happens with UserA's is different.
If user A was in the process of making a change, they will get a pop up to show them what changed, and what their new value will be if they click save and asks them which change they want to keep. If UserA doesn't have a change it does an ajax postback with a notification bar at the top that says "Record Change: Refreshed Automatically" that expires after a few seconds.
The Cons to this,
1. It's very complex
2. It won't catch insert/update/delete operations from outside of the application.
In my case, 2 won't happen and if 2 does happen it's by myself or another dev who knows how to manually create the notify que requests "building an admin page for that".
You can use https://maxwells-daemon.io to do so.
It is based on mysql bin logs, when changes in database is occurred it will send json message with updates to kafka, rabbitmq or other streaming platforms

How can I let users register my product online?

I've a MySql database hosted in my web site, with a table named UsrLic
Where any one wants to buy my software must register and enter his/her Generated Machine Key (+ username, email ...etc).
So my question is:
I want to automate this process from my software, how this Process will be?
Should I connect and update my database directly from my software ( and this means I must save all my database connection parameters in it * my database username , password , server * and then use ADO or MyDac to connect to this database ? and if yes how secure is this process ?
or any other suggestions .
I recommend creating an API on your web site in PHP and calling the API from Delphi.
That way, the database is only available to your web server and not to the client application, ever. In fact, you should run your database on localhost or with a private IP so that only machines on the same physical network can reach it.
I have implemented this and am implementing it again as we speak.
PHP
Create a new file named register_config.php. In this file, setup your MySQL connection information.
Create a file named register.php. In this file, put your registration functions. From this file, include 'register_config.php'. You will pass parameters to the functions you create here, and they will do the reading and writing to your database.
Create a file named register_api.php. From this file, include 'register.php'. Here, you will process POST or GET variables that are sent from your client application, call functions in register.php, and return results back to the client, all via HTTP.
You will have to research connecting to and querying a MySQL database. The W3Schools tutorials will have you doing this very quickly.
For example:
Your Delphi program calls https://mysite/register_api.php with Post() and sends the following values:
name=Marcus
email=marcus#gmail.com
Here's how the beginning of register_api.php might look:
// Our actual database and registration functions are in this library
include 'register.php';
// These are the name value pairs sent via POST from the client
$name = $_POST['name'];
$email = $_POST['email'];
// Sanitize and validate the input here...
// Register them in the DB by calling my function in register.php
if registerBuyer($name, $email) {
// Let them know we succeeded
echo "OK";
} else {
// Let them know we failed
echo "ERROR";
}
Delphi
Use Indy's TIdHTTP component and its Post() or Get() method to post data to register_api.php on the website.
You will get the response back in text from your API.
Keep it simple.
Security
All validation should be done on the server (API). The server must be the gatekeeper.
Sanitize all input to the API from the user (the client) before you call any functions, especially queries.
If you are using shared web hosting, make sure that register.php and register_config.php are not world readable.
If you are passing sensitive information, and it sounds like you are, you should call the registration API function from Delphi over HTTPS. HTTPS provides end to end protection so that nobody can sniff the data being sent off the wire.
Simply hookup a TIdSSLIOHandlerSocketOpenSSL component to your TIdHTTP component, and you're good to go, minus any certificate verification.
Use the SSL component's OnVerifyPeer event to write your own certificate verification method. This is important. If you don't verify the server side certificate, other sites can impersonate you with DNS poisoning and collect the data from your users instead of you. Though this is important, don't let this hold you up since it requires a bit more understanding. Add this in a future version.
Why don't you use e.g. share*it? They also handle the buying process (i don't see how you would do this for yourself..) and let you create a reg key through a delphi app.