Module install: script install.mysql.utf8.sql does not create table - joomla

The SQL install script install.mysql.utf8.sql does not create the table.
My module manifest file is:
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" client="site" method="upgrade">
<name>Data Entry module</name>
<author>Md Masum</author>
<version>1.0.0</version>
<description>This is a data entry module. by this module we can store various data in our custom table into joomla database</description>
<files>
<filename>mod_entry.xml</filename>
<filename module="mod_entry">mod_entry.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
<folder>sql</folder>
</files>
<install>
<sql>
<file driver="mysql" charset="utf8">sql/mysql/install.mysql.utf8.sql</file>
<file driver="sqlazure" charset="utf8">sql/sqlazure/install.sqlazure.utf8.sql</file>
</sql>
</install>
<uninstall>
<sql>
<file driver="mysql" charset="utf8">sql/mysql/uninstall.mysql.utf8.sql</file>
<file driver="sqlazure" charset="utf8">sql/sqlazure/uninstall.sqlazure.utf8.sql</file>
</sql>
</uninstall>
<update>
<schemas>
<schemapath type="mysql">sql/mysql/updates</schemapath>
<schemapath type="sqlazure">sql/sqlazure/updates</schemapath>
</schemas>
</update>
<config>
</config>
</extension>
SQL file (install.mysql.utf8.sql) contains:
CREATE TABLE IF NOT EXISTS `#__student_profile` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
`roll` int(10) NOT NULL,
`class` int(2) NOT NULL,
`section` varchar(25) NOT NULL,
`subject` varchar(25) NOT NULL,
`father_name` varchar(25) NOT NULL,
`mother_name` varchar(25) NOT NULL,
`email` varchar(25) NOT NULL,
`address` varchar(50) NOT NULL,
`phone` int(14) NOT NULL,
`date_birth` date NOT NULL,
`date_addmission` date NOT NULL,
`religion` varchar(10) NOT NULL,
`gender` varchar(6) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

Manifest file is OK.
SQL file is also OK.
I've managed to install your module without any issues.
My guess is that you already have the module installed. If the module is already registered with Joomla, when creating the install kit and installing it, it will detect that it's already installed and it will NOT install it again but it will just update it (using the SQL update statements). Which means that install.mysql.utf8.sql will not get executed a second time.
Uninstall the module from Joomla and do a fresh reinstall, it should work.
Hope this helps.

Related

How to make a relation field that shows a list of users with additionnal fields

The plugin I've created has two tables with these structures :
CREATE TABLE notifications (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`created_at` TIMESTAMP NULL DEFAULT NULL,
`updated_at` TIMESTAMP NULL DEFAULT NULL,
`sent_at` DATETIME NULL DEFAULT NULL,
`title` VARCHAR(191) NOT NULL COLLATE 'utf8mb4_unicode_ci',
`message` TEXT NOT NULL COLLATE 'utf8mb4_unicode_ci',
`photo` VARCHAR(191) NOT NULL COLLATE 'utf8mb4_unicode_ci',
`icon` VARCHAR(191) NOT NULL COLLATE 'utf8mb4_unicode_ci'
)
CREATE TABLE notification_recipients(
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`created_at` TIMESTAMP NULL DEFAULT NULL,
`updated_at` TIMESTAMP NULL DEFAULT NULL,
`notification_id` INT(11) NOT NULL,
`user_id` INT(11) NOT NULL,
`seen` TINYINT(1) NOT NULL,
`archived` TINYINT(1) NOT NULL
)
I can't figure out how to create a relation to show a backend select field where I can select users to get the notification, what should be done in the model.
I will later process the form in the controller in order to create the notification_recipients line to every user selected.
After reading and watching the tutorial about relations, I've come to understand I might need a pivot table.
But I need the notification_recipients table in order to process the notification later to show custom queries in frontend (seen and archived fields will determine the visibility in frontend).
How can I do that ? I don't understand the relationship I'm trying to build, shouw I have a third table ?
Thank you, best regards.
Update (solution found) :
I added a Checkbox List named "users".
According to the docs of OctoberCMS, you can add options from the model to a Radio field, and Checkbox Lists work the same way.
For now, I got it working by doing this in the Model used for the form:
use RainLab\User\Models\User;
...
public function getUsersOptions($value, $formData)
{
$users = User::all();
$mapped = $users->mapWithKeys(function ($item) {
return [$item['id'] => $item['name']];
});
return $mapped;
}
It worked great and I'm getting all users with their ids.

Role based dashboard in spring security

CREATE TABLE `role_details` (
`role_id` int(11) NOT NULL AUTO_INCREMENT,
`role_name` varchar(45) DEFAULT NULL,
`role_desc` varchar(100) DEFAULT NULL,
`rights` varchar(300) DEFAULT NULL,
PRIMARY KEY (`role_id`)
)
CREATE TABLE `user_details` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`display_name` varchar(45) DEFAULT NULL,
`password` varchar(45) DEFAULT NULL,
`emp_id` int(11) DEFAULT NULL,
`role` varchar(45) DEFAULT NULL,
`email` varchar(45) DEFAULT NULL,
`mobile` varchar(45) DEFAULT NULL,
`creation_time` datetime DEFAULT CURRENT_TIMESTAMP,
`status` varchar(45) DEFAULT NULL,
PRIMARY KEY (`user_id`)
)
This is my database schema. I am using spring security.
But I am confused...what I need to write in spring-security.xml ?
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query=
"SELECT * FROM hmis_db.user_details where display_name=? and status='active'"
authorities-by-username-query=
"**QUESTION** " />
</authentication-provider>
</authentication-manager>
Actually, I want to create Role based dashboard. and 'rights' in role_details table that specifies the access menu list..and according it it will generate role based dashboard.
Actually I can't see the relationship between your UserDetails table and the RoleDetails one, maybe I'm losing something.
When I have made such a kind of entities schemas, I allways made a 1-to-n relations between Users and roles, so one user can have one role or more.
But assumming you are conguring a 1-1 relation from user to role, and assuming the ROLE_xxx you are looking for is on the role field in UserDetails table, your authorities-by-username-query must be more or less like this:
"select display_name as username, role as authority from user_details where display_name =? "
If the field role in user_details is the foreign key which must match the field role_name in role_details, and rigths are actually the authorities which are referenced in access elements of security_intercept urls, it should be this way:
"select u.display_name as username, r.rights as authority
from user_details as u INNER JOIN role_details as r ON u.role = r.role_name
where u.display_name =? "
But here you might have a trouble if rights are a comma separated list of authorities. authorities-by-username-query expects to receive a list of rows with an authority in each of this rows. If this is what you were seeking, you should consider changing the schema or making even a view of the tables which returns a right per row result
EDIT: I should do this way:
This is the creation script:
CREATE TABLE IF NOT EXISTS `role_details` (
`role_id` INT(11) NOT NULL AUTO_INCREMENT,
`role_name` VARCHAR(45) NULL DEFAULT NULL,
`role_desc` VARCHAR(100) NULL DEFAULT NULL,
`role_authority` VARCHAR(300) NOT NULL,
PRIMARY KEY (`role_id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
CREATE TABLE IF NOT EXISTS `user_details` (
`user_id` INT(11) NOT NULL AUTO_INCREMENT,
`display_name` VARCHAR(45) NULL DEFAULT NULL,
`password` VARCHAR(45) NULL DEFAULT NULL,
`emp_id` INT(11) NULL DEFAULT NULL,
`email` VARCHAR(45) NULL DEFAULT NULL,
`mobile` VARCHAR(45) NULL DEFAULT NULL,
`creation_time` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
`status` TINYINT(1) NULL DEFAULT 0,
PRIMARY KEY (`user_id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
CREATE TABLE IF NOT EXISTS `user_role_details` (
`user_details_user_id` INT(11) NOT NULL,
`role_details_role_id` INT(11) NOT NULL,
PRIMARY KEY (`user_details_user_id`, `role_details_role_id`),
INDEX `fk_user_details_has_role_details_role_details1_idx` (`role_details_role_id` ASC),
INDEX `fk_user_details_has_role_details_user_details_idx` (`user_details_user_id` ASC),
CONSTRAINT `fk_user_details_has_role_details_user_details`
FOREIGN KEY (`user_details_user_id`)
REFERENCES `user_details` (`user_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_user_details_has_role_details_role_details1`
FOREIGN KEY (`role_details_role_id`)
REFERENCES `role_details` (`role_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
Note I deleted column 'role' in user_details, renamed 'rights' to 'role_authority' in role_details and changed 'status' from varchar to tinyint(1) to use it as boolean.
Then, the user details sqls:
users-by-username-query=
"SELECT display_name as username, password, status as enabled
FROM user_details as u WHERE u.display_name = ? and status = 1;"
authorities-by-username-query=
"Select u.display_name as username, r.role_authority as authority
FROM
user_details as u
INNER JOIN user_role_details as urd ON u.user_id = urd.user_details_user_id
INNER JOIN role_details as r ON urd.role_details_role_id = r.role_id
WHERE u.display_name = ?"
This way you can have multiple roles binded to each user
Refer to following link that covers basics and example http://en.tekstenuitleg.net/blog/spring-security-with-roles-and-rights
Once you familiarize yourself with basics, please look deeper into Spring Security documentation https://docs.spring.io/spring-security/site/docs/3.0.x/reference/ns-config.html before you implement that code for production.
If you are using Spring Security 4, you may prefer annotations based configurations like
#Configuration
#EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
#Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("userpwd").roles("USER");
auth.inMemoryAuthentication().withUser("admin").password("adminpwd").roles("ADMIN");
}
#Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.antMatchers("/admin/**").access("hasRole('ADMIN')")
.and().formLogin()
.and().exceptionHandling().accessDeniedPage("/Access_Denied");
}
}

SpringMVC and Mybatis can't run 'insert'

When I click submit in localhost:8080/myregister.jsp(controller:
localhost:8080/user/register),it gets:
Request processing failed; nested exception is
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
com.cn.hnust.dao.UserMapper.insert
When I click submit in localhost:8080/login.jsp,(controller: localhost:8080/user/login),it works.
[MYSQL:
DROP TABLE IF EXISTS user_t;
CREATE TABLE user_t (
username varchar(40) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY (username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
]
I use mybatis-generator-core-1.3.2 to general UserMapper.xml,but why only the 'insert' function can't run?
The whole Maven project is in github:https://github.com/Bonsen/Spring-SpringMVC-mybatis.

Spring security remember me

As per this link, I'm trying to implement the Persistent Token Approach for the "remember me" functionality. The tokens are stored in my database (postgres). I have the datasource set up properly, however, when I try doing:
<remember-me data-source-ref="dataSource" />
My database does not get populated with the token data automatically. Otherwise, the "remember me" functionality works well (only the database doesn't get populated automatically). Any ideas why?
Table ddl:
create table users(
uid serial primary key,
username varchar(255) not null,
password varchar(255) not null,
firstname varchar(255) not null,
lastname varchar(255) not null,
enabled boolean not null,
constraint cs_username_unq unique(username),
constraint cs_uid_username_unq unique(uid, username)
);
create table authorities (
username varchar(255) not null,
authority varchar(255) not null,
constraint fk_authorities_users foreign key(username) references users(username)
);
create unique index ix_auth_username on authorities (username,authority);
create table persistent_logins (
username varchar(255) not null,
series varchar(255) primary key,
token varchar(255) not null,
last_used timestamp not null
);

FULL TEXT SEARCH in cakephp ? any example

I am using ordinary search functionality in my business controller . but
now need to implement FULL TEXT SEARCH with paginate can any one give idea or sample ?
I am using MySQL with MyISAM tabes
and this my table structure, fields marked bold are need to use in
search
CREATE TABLE IF NOT EXISTS businesses (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
created date NOT NULL,
modified datetime NOT NULL,
user_id bigint(20) NOT NULL,
slug varchar(255) NOT NULL,
**`name` varchar(255) NOT NULL,**
**street_name varchar(255) DEFAULT NULL,**
**shopping_center varchar(255) DEFAULT NULL,**
state_id int(10) NOT NULL,
suburb_id int(10) NOT NULL,
zip_code varchar(12) DEFAULT NULL,
website varchar(250) DEFAULT NULL,
email varchar(255) DEFAULT NULL,
phone_no varchar(255) NOT NULL,
mobile_no varchar(255) DEFAULT NULL,
fax varchar(255) DEFAULT NULL,
is_active tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
After you have created your FULLTEXT indices it's not different at all from normal paginate conditions, you just need to construct your SQL a little more manually and most importantly escape the user input manually.
$query = 'foobar'; // the user input to search for
$escapedQuery = $this->Business->getDataSource()->value($query);
$this->paginate['conditions'] = array("MATCH (Business.name) AGAINST ($escapedQuery)");
$businesses = $this->paginate();

Resources