Commit bcf6bf1f by Dirk Benkert

added cli task cleanup

parent 96aeeb38
# Installation
get zip package from https://gitlab.dirk-benkert.de/zf2/share
or clone project via git
run the following command to install dependencies via composer.
```
php composer.phar self-update
php composer.phar install --prefer-dist --optimize-autoloader
```
# Configuration
rename config/autoload/local.php.dist to config/autoload/local.php and edit with an editor
```
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'unix_socket' => '/path/to/local/socket',
//'host' => 'database-ip',
//'port' => '3306',
'user' => 'database-user',
'password' => 'database-password',
'dbname' => 'database-name',
),
)
)
),
'share-application' => array(
'physical-path' => __DIR__ . '../../data/files/',
),
```
enter you database credentials and modify the path where the uploaded files are stored if necessary
Make shure data/* is writeable
# Setup
after that you should be able to access the application with your web browser and see the login page.
To set up the database and insert initial data run the following commands.
```
vendor/bin/doctrine-module orm:schemat-tool:create
vendor/bin/doctrine-module data-fixture:import --append
```
**If you use data-fixture:import without --append all data in your database will be purged!**
This data-fixture import creates a single user "admin" with password "admin".
You can now login and access User administration to create a user and set your own password.
Delete the admin user after you created a user for yourself.
......@@ -3,8 +3,10 @@ return array(
'modules' => array(
'DoctrineModule',
'DoctrineORMModule',
'DoctrineDataFixtureModule',
'Administration',
'Application',
'Cli',
),
'module_listener_options' => array(
'config_glob_paths' => array(
......
......@@ -25,4 +25,17 @@ return array(
'Zend\Session\Validator\HttpUserAgent',
),
),
'service_manager' => array(
'allowOverride' => true,
'factories' => array(
//'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
'Zend\Authentication\AuthenticationService' => function($serviceManager) {
// If you are using DoctrineORMModule:
return $serviceManager->get('doctrine.authenticationservice.orm_default');
},
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
),
);
......@@ -12,43 +12,17 @@
* credentials from accidentally being comitted into version control.
*/
return array(
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
'Zend\Authentication\AuthenticationService' => function($serviceManager) {
// If you are using DoctrineORMModule:
return $serviceManager->get('doctrine.authenticationservice.orm_default');
},
'Admin\Service\Filesystem' => function ($serviceManager) {
$object = new Admin\Service\Filesystem();
$object->setServiceLocator($serviceManager);
$object->setRootPath('/var/data/');
$object->setBaseUrl('/projects/Vogel-Druck/Triaz/media-storage-application/');
return $object;
},
'Admin\Service\Softkat' => function($serviceManager) {
$object = new Admin\Service\Softkat();
$object->setServiceLocator($serviceManager);
$object->setRestUrl('http://restmedia:restmedia@192.168.130.146:8089/softkat/rest/media/');
$object->setTimeout(10);
//$object->setDebugMode();
//$object->setRestUrl('http://restmedia:asdfasfasdf@192.168.130.146:8089/softkat/rest/media/');
return $object;
},
),
),
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'unix_socket' => '/usr/local/zend/mysql/tmp/mysql.sock',
'port' => '3306',
'user' => 'media-storage',
'password' => 'media-storage',
'dbname' => 'media-storage',
'unix_socket' => '/path/to/local/socket',
//'host' => 'database-ip',
//'port' => '3306',
'user' => 'database-user',
'password' => 'database-password',
'dbname' => 'database-name',
),
)
)
......
......@@ -14,6 +14,7 @@ use Zend\Mvc\ModuleRouteListener;
use Zend\ModuleManager\ModuleManager;
use Zend\Session\SessionManager;
use Zend\Session\Container;
use Zend\Console\Request as ConsoleRequest;
class Module {
......@@ -23,7 +24,6 @@ class Module {
public function onBootstrap($e) {
//$eventManager = $e->getApplication()->getEventManager();
//[0] => route
//[1] => dispatch
//[2] => bootstrap
......@@ -36,7 +36,7 @@ class Module {
$this->initAcl($e);
$em = $e->getApplication()->getEventManager();
$em = $e->getApplication()->getEventManager();
$em->attach(\Zend\Mvc\MvcEvent::EVENT_ROUTE, array($this, 'checkAcl'));
}
......@@ -113,16 +113,21 @@ class Module {
$acl = $e->getViewModel()->acl;
try {
if (!$e->getViewModel()->acl->isAllowed($userRole, $route)) {
// sends User to 404 error page making missing permissions look like the page does not exists
// which is fine for now
$response = $e->getResponse();
$response->setStatusCode(404);
$request = $e->getRequest();
if (!$request instanceof ConsoleRequest) {
if (!$e->getViewModel()->acl->isAllowed($userRole, $route)) {
// sends User to 404 error page making missing permissions look like the page does not exists
// which is fine for now
$response = $e->getResponse();
$response->setStatusCode(404);
}
}
} catch (\Zend\Permissions\Acl\Exception\InvalidArgumentException $ex) {
// resource (e.g. path) is not defined in the acl so an InvalidArgument Exception is thrown
error_log($ex);
$response = $e->getResponse();
$response->setStatusCode(404);
}
}
}
......@@ -16,7 +16,7 @@ return array(
'controller_plugins' => array(
'invokables' => array(
'PaginationFilterSort' => 'Administration\Controller\Plugin\PaginationFilterSort',
'Crud' => 'Administration\Controller\Plugin\Crud',
'Crud' => 'Administration\Controller\Plugin\Crud',
)
),
'router' => array(
......@@ -29,11 +29,6 @@ return array(
'type' => 'Literal',
'options' => array(
'route' => '/administration',
//'defaults' => array(
// '__NAMESPACE__' => 'Administration\Controller',
// 'controller' => 'Index',
// 'action' => 'index',
//),
),
'may_terminate' => true,
'child_routes' => array(
......
......@@ -5,11 +5,14 @@ namespace Administration\Controller\Plugin;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
use Zend\Json\Json;
use Zend\View\Model\ViewModel;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Application\Util\Text;
class Crud extends AbstractPlugin {
const ENTITY = 'entity';
const ID_COLUMN = 'id';
const DEFAULT_VALUES = 'defaultValues';
const FORM = 'form';
const ROUTE = 'route';
const EDIT_TEMPLATE = 'editTemplate';
......@@ -56,11 +59,14 @@ class Crud extends AbstractPlugin {
$entity = $this->getEntity();
$message = $this->parseMessage(self::MSG_ENTRY_DELETED, $entity);
try {
$persistor = $this->getPersistor();
$persistor->remove($entity);
$persistor = $this->getPersistor();
$persistor->remove($entity);
$controller->flashMessenger()->addSuccessMessage($message);
$controller->flashMessenger()->addSuccessMessage($message);
} catch (ForeignKeyConstraintViolationException $ex) {
$controller->flashMessenger()->addErrorMessage(Text::translate('ForeignKeyContraintViolation'));
}
return $this->redirect();
}
......@@ -115,8 +121,11 @@ class Crud extends AbstractPlugin {
error_log(print_r($form->getMessages(), true));
$result = false;
} else {
$persistor->persist($entity, $form->getData());
$finalData = $form->getData();
if (false === $editMode && isset($this->options[self::DEFAULT_VALUES])) {
$finalData = array_merge($finalData, $this->options[self::DEFAULT_VALUES]);
}
$persistor->persist($entity, $finalData);
$controller->flashMessenger()->addSuccessMessage($this->parseMessage($editMode, $entity));
}
}
......
......@@ -19,6 +19,7 @@ use Zend\View\Model\ViewModel;
use Application\Controller\ControllerAbstract;
use Application\Entity\User;
use Administration\Form\UserForm;
use Zend\Stdlib\Parameters;
class UserController extends ControllerAbstract {
......@@ -96,6 +97,7 @@ class UserController extends ControllerAbstract {
return array(
Plugin\Crud::ENTITY => 'Application\Entity\User',
Plugin\Crud::DEFAULT_VALUES => array('created' => time()),
Plugin\Crud::ID_COLUMN => 'id',
Plugin\Crud::FORM => new UserForm($this->getServiceLocator(), $editMode),
Plugin\Crud::ROUTE => array(
......
......@@ -36,7 +36,7 @@ abstract class AbstractPersistor implements PersistorInterface {
if (is_array($entity)) {
$setterParameter = $entity['setterParameter'];
$entity = $entity['name'];
$entity = $entity['entity'];
}
if ($setterParameter == 'array') {
......@@ -47,7 +47,7 @@ abstract class AbstractPersistor implements PersistorInterface {
foreach ($data[$name] as $entityId) {
$entities[] = $controller->getEntityManager()->find($entity, $entityId);
}
$data[$name] = $entities;
} else {
$object = $controller->getEntityManager()->find($entity, $data[$name]);
......
......@@ -14,6 +14,7 @@ use Zend\Mvc\ModuleRouteListener;
use Zend\ModuleManager\ModuleManager;
use Zend\Session\SessionManager;
use Zend\Session\Container;
use Zend\Console\Request as ConsoleRequest;
class Module {
......@@ -159,16 +160,20 @@ class Module {
}
$acl = $e->getViewModel()->acl;
try {
if (!$e->getViewModel()->acl->isAllowed($userRole, $route)) {
// sends User to 404 error page making missing permissions look like the page does not exists
// which is fine for now
$response = $e->getResponse();
$response->setStatusCode(404);
$request = $e->getRequest();
if (!$request instanceof ConsoleRequest) {
if (!$e->getViewModel()->acl->isAllowed($userRole, $route)) {
// sends User to 404 error page making missing permissions look like the page does not exists
// which is fine for now
$response = $e->getResponse();
$response->setStatusCode(404);
}
}
} catch (\Zend\Permissions\Acl\Exception\InvalidArgumentException $ex) {
// resource (e.g. path) is not defined in the acl so an InvalidArgument Exception is thrown
error_log($ex);
$response = $e->getResponse();
$response->setStatusCode(404);
}
......@@ -188,20 +193,24 @@ class Module {
}
public function initLocale(\Zend\Mvc\MvcEvent $e) {
$session = new Container('locale');
$default = 'en_US';
$request = $e->getRequest();
if (!$request instanceof ConsoleRequest) {
$session = new Container('locale');
$default = 'en_US';
if (isset($session->locale)) {
$default = $session->locale;
}
if (isset($session->locale)) {
$default = $session->locale;
}
$locale = $e->getRequest()->getQuery('lang', $default);
$locale = $e->getRequest()->getQuery('lang', $default);
$translator = $e->getApplication()->getServiceManager()->get('mvcTranslator');
$translator->setLocale($locale);
$translator = $e->getApplication()->getServiceManager()->get('mvcTranslator');
$translator->setLocale($locale);
\Zend\Validator\AbstractValidator::setDefaultTranslator($translator);
\Zend\Validator\AbstractValidator::setDefaultTranslator($translator);
$session->locale = $locale;
$session->locale = $locale;
}
}
}
......@@ -115,6 +115,7 @@ return array(
'bootstrapTextarea' => 'Application\Form\View\Helper\BootstrapTextarea',
'bootstrapSelect' => 'Application\Form\View\Helper\BootstrapSelect',
'pageNavigation' => 'Application\View\Helper\PageNavigation',
'alertBox' => 'Application\View\Helper\AlertBox',
//'renderTable' => 'Admin\View\Helper\RenderTable',
//'renderEmailLink' => 'Admin\View\Helper\RenderEmailLink',
//'renderDateValue' => 'Admin\View\Helper\RenderDateValue',
......@@ -147,6 +148,9 @@ return array(
'credential_callable' => 'Application\Entity\User::checkPassword',
),
),
'fixture' => array(
'Application_fixture' => __DIR__ . '/../src/Application/Fixture',
),
),
'session' => array(
'config' => array(
......
......@@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: share-application\n"
"POT-Creation-Date: 2015-09-08 09:53+0200\n"
"PO-Revision-Date: 2015-09-08 09:58+0200\n"
"PO-Revision-Date: 2015-09-09 13:47+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: de\n"
......@@ -34,7 +34,7 @@ msgstr "Benutzer"
#: src/Application/Controller/JsonController.php:95
#: view/application/index/profile.phtml:3
msgid "Profil"
msgstr "Profil:"
msgstr "Profil"
#: src/Application/Controller/JsonController.php:99
msgid "logout"
......
......@@ -21,7 +21,6 @@ use Application\Entity\User;
use Application\Form\FolderForm;
use Administration\Controller\Plugin\PaginationFilterSort;
use Administration\Controller\Plugin\Crud;
use Zend\Stdlib\Parameters;
class FolderController extends ControllerAbstract {
......@@ -100,6 +99,7 @@ class FolderController extends ControllerAbstract {
return array(
Crud::ENTITY => 'Application\Entity\Folder',
Crud::PERSISTOR => 'Application\CrudPersistor\Folder',
Crud::CHILD_ENTITIES => array(
'users' => array(
'entity' => 'Application\Entity\User',
......
<?php
/**
* Description for IndexControll
*
......@@ -7,14 +8,17 @@
* @copyright Copyright (c) Vogel-Druck
* @version 1.0
*/
namespace Application\Controller;
use Application\Controller\ControllerAbstract;
use Application\Form\LoginForm;
use Administration\Form\UserForm;
use Zend\View\Model\ViewModel;
use Application\Util\Text;
class IndexController extends ControllerAbstract {
/**
* Index action, redirects to storages/index if user is logged in, provides and validates login form if not.
*
......@@ -54,9 +58,9 @@ class IndexController extends ControllerAbstract {
return new ViewModel(
array(
'form' => $form,
)
array(
'form' => $form,
)
);
}
......@@ -72,23 +76,13 @@ class IndexController extends ControllerAbstract {
$this->redirectTo();
}
/*public function pageAction() {
$authService = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
return new ViewModel(
array(
'identity' => $authService->getIdentity(),
)
);
}*/
public function folderAction() {
$authService = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
return new ViewModel(
array(
'identity' => $authService->getIdentity(),
)
array(
'identity' => $authService->getIdentity(),
)
);
}
......@@ -100,17 +94,15 @@ class IndexController extends ControllerAbstract {
$userForm = new UserForm($this->getServiceLocator(), true);
$userForm->setData($user->getData());
return new ViewModel(
array(
return new ViewModel(array(
'user' => $user,
'form' => $userForm,
)
);
));
}
public function saveprofileAction() {
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost();
$data = $this->getRequest()->getPost()->toArray();
$authService = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
$identity = $authService->getIdentity();
......@@ -122,10 +114,12 @@ class IndexController extends ControllerAbstract {
}
$user = $this->getEntityManager()->find('Application\Entity\User', $data['id']);
$userData = $user->getData();
$editMode = true;
$userForm = new UserForm($this->getServiceLocator(), $editMode);
$userForm->setData($data);
$userForm->setData(array_merge($userData, $data));
if ($userForm->isValid()) {
$user->setService($this);
......@@ -138,6 +132,7 @@ class IndexController extends ControllerAbstract {
} else {
error_log(print_r($userForm->getData(), true));
error_log(print_r($userForm->getMessages(), true));
$this->flashMessenger()->addErrorMessage(Text::translate('Profil could not be saved.'));
}
}
......@@ -150,4 +145,5 @@ class IndexController extends ControllerAbstract {
return $viewModel;
}
}
......@@ -50,9 +50,11 @@ class File extends \Administration\CrudPersistor\Entity {
if (!is_dir(dirname($path))) {
mkdir(dirname($path));
chmod(dirname($path), 0777);
}
move_uploaded_file($data['upload']['tmp_name'], $path);
chmod($path, 0777);
return $path;
}
......
<?php
namespace Application\CrudPersistor;
use Application\Service\Path;
class Folder extends \Administration\CrudPersistor\Entity {
public function remove($entity) {
$controller = $this->getService()->getController();
$pathService = new Path($this->getService()->getController()->getServiceLocator());
rmdir($pathService->filePath($entity->label));
$controller->getEntityManager()->remove($entity);
$controller->getEntityManager()->flush();
}
}
......@@ -57,9 +57,9 @@ class Folder extends AbstractEntity {
$this->files = new ArrayCollection();
}
public function setExpires($timestamp) {
public function setExpires($dateString) {
$this->expires = new DateTime();
$this->expires->setTimestamp(strtotime($timestamp));
$this->expires->setTimestamp(strtotime($dateString));
}
public function addUser(\Application\Entity\User $user) {
......
......@@ -26,7 +26,7 @@ class User extends AbstractEntity {
* @ORM\Column(type="integer")
*/
protected $id;
/**
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $email;
......
<?php
namespace Application\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Application\Entity\User;
class UserFixtureLoader implements FixtureInterface {
public function load(ObjectManager $manager) {
$user = new User();
$user->setData(array(
'email' => 'admin',
'password' => 'admin',
'isadmin' => true,
'caninvite' => true,
'cancreatefolders' => true,
'canuploadfiles' => true,
'created' => time(),
'createdviainvite' => false
));
$manager->persist($user);
$manager->flush();
}
}
......@@ -2,6 +2,7 @@
namespace Application\Repository;
use Doctrine\ORM\Tools\Pagination\Paginator as OrmPaginator;
use \DateTime;
class FolderRepository extends PaginationFilterSortRepository implements AuthenticationAwareInterface
{
......@@ -53,6 +54,17 @@ class FolderRepository extends PaginationFilterSortRepository implements Authent
return $paginator;
}
public function getExpiredFolders(DateTime $dateTime) {
$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();
$qb->select('f')
->from('\Application\Entity\Folder', 'f')
->where('f.expires < :expires')
->setParameter('expires', $dateTime);
return $qb->getQuery()->getResult();
}
protected function addFilter($qb, $filter_label) {
if ($filter_label != false) {
$qb->andWhere('f.label LIKE :label')
......
......@@ -50,6 +50,27 @@ class UserRepository extends PaginationFilterSortRepository
return $query->getResult();
}
public function getUnusedUsers() {
$em = $this->getEntityManager();
$sqb = $em->createQueryBuilder();
$sqb->select('u.id')
->distinct()
->from('\Application\Entity\User', 'u')
->join('u.folders', 'f');
$userids = $sqb->getQuery()->getArrayResult();
$qb = $em->createQueryBuilder();
$qb->select('u')
->from('\Application\Entity\User', 'u')
->where('u.createdviainvite = :createdviainvite')
->setParameter('createdviainvite', true)
->andWhere('u.id NOT IN (:userids)')
->setParameter('userids', $userids);
return $qb->getQuery()->getResult();
}
protected function getSelect() {
$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();
......
......@@ -2,6 +2,7 @@
namespace Application\Service;
use Application\Entity\User as UserEntity;
use Zend\Validator\EmailAddress;
class User extends AbstractService {
......@@ -21,27 +22,33 @@ class User extends AbstractService {
$folder->users = null;
$this->getEntityManager()->persist($folder);
$validator = new EmailAddress();
foreach ($userlist as $userid => $value) {
$user = $this->getEntityManager()->find('Application\Entity\User', $userid);
if (!is_numeric($userid)) {
$user = new UserEntity();
$service = new Password();
$user->setData(array(
'email' => $userid,
'password' => $service->generate(),
'isadmin' => false,
'caninvite' => false,
'cancreatefolders' => false,
'canuploadfiles' => false,
'created' => time(),
'createdviainvite' => true
));
$this->getEntityManager()->persist($user);
$userid = $user->id;
$value = $user->id;
if($validator->isValid($userid)) {
$user = new UserEntity();
$service = new Password();
$user->setData(array(
'email' => $userid,
'password' => $service->generate(),
'isadmin' => false,
'caninvite' => false,
'cancreatefolders' => false,
'canuploadfiles' => false,
'created' => time(),
'createdviainvite' => true
));
$this->getEntityManager()->persist($user);
$userid = $user->id;
$value = $user->id;
} else {
$user = false;
}
}
if ($user && $userid == $value) {
......
<?php
/**
* View Helper
*
* @package Application_View_Helper
* @author Dirk Benkert <mail@dirk-benkert.de>
* @copyright Copyright (c) Dirk Benkert
* @version 1.0
*/
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
class AlertBox extends AbstractHelper {