Dieses Blog durchsuchen

Samstag, 16. Juli 2016

mysql: add / editing a foreign key after database was created

This task is simple but offten needed.

If you have created a databasetable and you forgot the foreignkeys, you can simply add it later via altering table.

Add a foreignkey


This key references the userid from users to a tupel in table posts. If a user gets deleted or updated the post will be deleted to0.

Deleting a foreign key

asdasd

Sonntag, 10. Juli 2016

Symfony 3.1 Add a encrypted passwordfield to your entity, controller and Form

If you have a passwordfield in your database you have to encrypt the passwordbefpre you can save it.

this task is pretty straight forward in symfony 3.1

Once you have created your entity (f. i BlogBundle\Entity\Users)
You have to implement the core security user  interface  to make the entity compatible to the encoder class. See my class to understand the mechanism:


Implement interfacemethods
You have to implement the last 2 methods (see class above) to fullfill the contract.

Modify security:
open app/config/security and add encoder like this:

clear cache after that

Add encoder to your user-controller


Add password and password confirmation field to your crud form

thats it

Install symphon2 on linux, create a project with database, crudforms and twittter bootstrap

 Today we want to create a simple blogapplication with symfony (3.1)

LEVEL: PHP Advanced / Symfony2 Novice

This blog will have 3 features
- Users (add, delete, edit, login)
- Posts (add, delete, edit)
- Replies (add, delete, edit)


You need to have PHP 5 or 7 and Mysql Server running


Install Symfony
$ sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
$ sudo chmod a+x /usr/bin/local/symfony


Create App 
php bin/console new blog 3.1

Create Bundle
php bin/console generate:bundle
- call it BlogBundle


Edit databaseconfiguration
open parameters.yml in config folder and edit databaseaccess

Create a database
php bin/console doctrine:database create
- call it blog

open a mysql client (fy mysql-workbench)

create needed tables

CREATE TABLE `replies` (
  `id` int(11) NOT NULL,
  `userid` int(11) DEFAULT NULL,
  `title` varchar(255) DEFAULT NULL,
  `content` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `firstname` varchar(255) DEFAULT NULL,
  `lastame` varchar(255) DEFAULT NULL,
  `username` varchar(50) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `isDeleted` tinyint(4) DEFAULT NULL,  `isActive` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `blog`.`posts` (
  `id` INT NOT NULL COMMENT '',
  `userid` INT NULL COMMENT '',
  `title` VARCHAR(255) NULL COMMENT '',
  `content` TEXT NULL COMMENT '',
  `isDeleted` TINYINT NULL COMMENT '',  `isActive` TINYINT NULL COMMENT '',
  PRIMARY KEY (`id`)  COMMENT '');

create entities from database:
php bin/console doctrine:mapping:import --force BlogBundle xml
php bin/console doctrine:mapping:convert annotation ./src
php bin/console doctrine:generate:entities BlogBundle 
 
 
Install twitter boodstrap crud bundle 
composer require triton/crud-generator
Add it to the AppKernel.php class:
new Lexik\Bundle\FormFilterBundle\LexikFormFilterBundle(), new Triton\Bundle\CrudBundle\TritonCrudBundle(), 
 
Optionally for the bootstrap theme, add this to your app/config/config.yml
twig:
form_themes:
- 'bootstrap_3_layout.html.twig'

 
generate crud controllers with twitter bootstrap look and feel 
php bin/console triton:generate:crud
 
 
  














Samstag, 2. Juli 2016

Install magento via commandline on a linux machine

1) Install composer on your machine


at the moment you have to have installed php 7.0.2 minumum
if you do not have a lamp stack installed, follow this very good guide
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/

add a mysql user with needed rights
GRANT ALL on *.* to 'peter'@'localhost' identified by 'yoursecretpassword';


install needed php extensions
apt-get install php7.0-gd php7.0-xml php7.0-mcrypt php7.0-curl php7.0-intl php7.0-mbstring php7.0-zip php7.0-mysql

 
get composer
follow https://getcomposer.org/download/

Create project with composer
2)composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /var/www/html/magento2

this downloads and installs magento2 under /var/www/magento2

Username / Password repo.magnto.com
during the installation your are ask for username and password to repo.magento.org

You have to create an account on https://marketplace.magento.com and create access keys.
After you have created private and public key, you have to use the public key as username and the privatekey as the password


make cli executable
cd /var/www/magento2 && chmod +x bin/magento

Database
create a database named magento2

navigate to installdir
cd /var/www/magento2

set accessrights (all for the first time)
chmod -R 777 *

execute installcommand
bin/magento setup:install --base-url=http://magento2.localhost/pub/ --language=en_US --backend-frontname=admin --db-host=localhost --db-name=magento2 --db-user=root --db-password=DBPASSWORD --admin-email=max@mustermann.de --admin-user=youradmin --admin-password=PASSWORD --admin-firstname=Max --admin-lastname=Mustermann

add sampledata and activate additional modules
bin/magento sampledata:deploy 
bin/magento setup:upgrade

you will be asked for username and password again. user your pubkey as username and private key as password 

enable devoloper-mode to see all php problems and get more information during runtime
bin/magento deploy:mode:set developer

deploy static content, otherwise styles are missing
bin/magento setup:static-content:deploy 


add domain to your /etc/hosts
nano etc/hosts
127.0.0.1 magento2-shop.local 

add apache-vhost entry to your installation
keep sure, you link into the pubditectory, otherwise the css files arent found






this article is based on:
http://alanstorm.com/magento-2-frontend-files-serving

and 

https://www.integer-net.de/magento-2-installation/





Donnerstag, 19. Mai 2016

Mal was anderes !

Deine Gefühle werden dein Schicksal

Achte auf deine Gefühle, denn sie werden zu Gedanken.
Achte auf deine Gedanken, denn sie werden zu Worten.
Achte auf deine Worte, denn sie werden zu Handlungen.
Achte auf deine Handlungen, denn sie werden zu Gewohnheiten.
Achte auf deine Gewohnheiten, denn sie werden dein Charakter. Achte auf deinen Charakter, denn er wird dein Schicksal.

Dienstag, 10. Mai 2016

Create a magento 1 api user programmaticly

If you want to add a user via method you can use the following code

1) the main function in a class Ibrams/Application/Model/User.php

2) the call

Dienstag, 26. April 2016

securty warning from magento

security Announcement Third-Party Themes and Extensions Are at Risk We recently learned that an SQL injection vulnerability has been found in several third-party themes and extensions. Extensions with the vulnerability include: EM (Extreme Magento) Ajaxcart EM (Extreme Magento) Quickshop MD Quickview SmartWave QuickView These extensions are used in several different themes, including Porto, Trego, and Kallyas from SmartWave. Other SmartWave themes may also be at risk. Vulnerable EM modules are used in some EM themes. The core Magento application is not impacted in any way by this vulnerability. We’ve received reports that the SQL injection vulnerability is potentially being exploited. If you currently use these extensions or themes, you should immediately contact the company from which you purchased the extensions or themes to request updated code. We understand that Themeforest, part of Envato Market, has already removed the vulnerability from the Porto theme, but the status of other themes and extensions is unknown. It is also important for you to evaluate all your Magento administrator accounts to make sure there are no unknown users and to reset all your administrator passwords. Please review the Magento Security Best Practices for more information on how to secure your site and use magereport.com to scan your site for missing patches or known issues. This update is part of our ongoing commitment to advise our merchants on security issues as we become aware of them. We thank you for your attention to this matter. Best regards, The Magento Team