Gediminas Morkevičius aka @l3pp4rd
mysql -u root database
On your localhost - development.
And on another shell - production
It is easy to mix the shells when running..
DELETE * FROM users
How to prevent this from happening?
Composer modules
{
"require": {
"symfony/symfony": "~2.7.0",
"symfony/monolog-bundle": "~2.7",
"symfony/swiftmailer-bundle": "~2.3",
"my-company/payments":"~1.0"
}
}
To prevent downloading vendor packages on deployment, we are building a release archive
gulp.task('archive', function(cb) {
spawn.exec('./bin/archive', function(err, stdout, stderr) {
if (err) {
gutil.log(gutil.colors.red('error'), ' => ', stdout);
} else {
gutil.log(gutil.colors.cyan('package'), ' => ', stdout);
}
cb(err);
})
});
gulp.task('package', function () {
runSequence('build', 'composer-minimize', 'composer-optimize', 'archive', 'composer-install', function (err) {
if (err) gutil.log(gutil.colors.red('error'), ' => ', err);
});
});
It is a very high probability that developer, tampers with vendor sources..
vim vendor/my-company/payments
And it just went to production
A fix was applied..
gulp.task('composer-minimize', function(cb) {
// and ensure that tampered vendors are reset!
spawn.exec('rm -rf vendor/{my-company} && composer install --no-scripts --no-dev', function(err, stdout, stderr) {
cb(err);
});
});
Transaction management
There are few things you always need to know about databases
Serialization deadlocks on MySQL is one of them
Unreadable and unmaintanable code
Nested if statements. Do you see a bug here?
function signupAction(Request $request)
{
$form = $this->createForm(new SignupType(), $user = new User());
$form->handleRequest($request);
if ($form->isValid()) {
$same = $this->repo('AppBundle:User')->findOneBy(['email' => $user->getEmail()]);
if (null !== $same) {
if ($same->isConfirmed()) {
$this->formError($form->get('email'), "already confirmed");
} else {
$this->get('mail')->user($same, 'activate');
}
} else {
$user->regenerateConfirmationToken();
$this->persist($user);
$this->flush();
$this->get('mail')->user($same, 'activate');
}
return $this->redirect($this->generateUrl('app_user_login'));
}
return ['form' => $form->createView()];
}
How about now?
function signupAction(Request $request)
{
$form = $this->createForm(new SignupType(), $user = new User());
$form->handleRequest($request);
if (!$form->isValid()) {
return ['form' => $form->createView()];
}
$same = $this->repo('AppBundle:User')->findOneBy(['email' => $user->getEmail()]);
if (null !== $same and $same->isConfirmed()) {
$this->formError($form->get('email'), "already confirmed");
}
if (null !== $same) {
$this->get('mail')->user($same, 'activate');
return $this->redirect($this->generateUrl('app_user_login'));
}
$user->regenerateConfirmationToken();
$this->persist($user);
$this->flush();
$this->get('mail')->user($same, 'activate');
$this->addFlash('success', 'Activation email was sent');
return $this->redirect($this->generateUrl('app_user_login'));
}
File session storage - does not scale
Be careful with IP tables
Cannot SSH anymore. Server is a blackbox
iptables -F
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
chmod -R 777
Late Friday releases
die(var_dump()) on weekend
Develop everything in smallest possible steps, otherwise you might not finish anything..
Initial commit on DoctrineExtensions
I failed so many projects, because I tried to publish something better, bigger, nicer