Because of a long series of events, I thought I lost a site completely due to my hosting company losing a server. Anyway, I'm trying to get back into a site sitting on a server with a cpanel I cant get to and a WHM I cant get to. I only have access to the root dir via ftp. I was able to reset my admin password using the method here https://www.drupal.org/node/1556488
I meant to also clear the flood table, but deleted it instead with db_drop_table('flood');
So, now I am getting a MYSQL error when I try to login. So, given I only have access to running php scripts to interact with the SQL database, can anyone help me figure out how to rebuild the flood table via the drupal db_create_table() method?
Much appreciated! This has been a nightmare.
I was able to rebuild my flood table with a php file ran from the drupal install directory with this in it: Just type in the url mysite.com/myphpfile.php to run it.
<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once DRUPAL_ROOT . '/includes/password.inc';
$schema = array();
$schema['flood'] = array(
'fields' => array(
'fid' => array(
'type' => 'int',
'length' => 11,
'not null' => TRUE,
),
'event' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'identifier' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'timestamp' => array(
'type' => 'int',
'length' => 11,
'not null' => TRUE,
),
'expiration' => array(
'type' => 'int',
'length' => 11,
'not null' => TRUE,
),
),
'primary key' => array('fid'),
);
db_create_table('flood', $schema['flood']);
print "Done. Please delete this file immediately!";
drupal_exit();
?>
Related
I am attempting to create a database and table for each customer registered from my codeigniter site, i am looking at the dbforge documentation and tried below code.
but error appeared, i want to make it dynamic for each customer so putting it on config/database.php is not available is there a way to prevent this?
i am new with codeigniter not sure if below code is also correct.
You have specified an invalid database connection group
(customer_LYWA) in your config/database.php file.
public function create_customer_database($code){
$database = $this->dbutil->database_exists('customer_'.$code);
if($database){
return "";
}else{
$this->dbforge->create_database('customer_'.$code);
$fields = array(
'blog_id' => array(
'type' => 'INT',
'constraint' => 5,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'blog_title' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'blog_author' => array(
'type' =>'VARCHAR',
'constraint' => '100',
'default' => 'King of Town',
),
'blog_description' => array(
'type' => 'TEXT',
'null' => TRUE,
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('blog_id', TRUE);
// gives PRIMARY KEY (blog_id)
$this->dbforge->add_key('blog_title');
// gives KEY (blog_title)
$otherdb = $this->load->database('customer_'.$code, TRUE);
$this->dbforge->create_table('blog');
return "created";
}
}
I think you are trying to create a table for each customer.
With that, I think you are confusing databases with tables. databases contain tables, so you will need to connect to the correct database in config/database.php, and use your script to create tables inside that database.
You don't need to create a new database for each customer. That would make things 100 times harder than they should be, and will be very hard to maintain.
I have written below code in custom_notifications.install file.
When I am trying to enable that module its giving me error "The website encountered an unexpected error. Please try again later."
kindly help me with this.
function custom_notifications_schema() {
$schema['custom_notification_log'] = array(
'fields' => array(
'cnl' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
'notification_type' => array('type' => 'varchar', 'length' => 64),
'notification_type_id' => array('type' => 'int', 'unsigned' => TRUE),
'uid' => array('type' => 'int', 'unsigned' => TRUE),
'viewed_on' => array('type' => 'int', 'unsigned' => TRUE),
)
);
return $schema;
}
A couple things to try:
1) Look at your dblog (Reports -> Recent log messages) for PHP errors providing more information.
2) Go to the Uninstall tab and see if your module is listed. If it is, then uninstall it, then attempt to re-install.
SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE. try removing the unsigned and not null keys for your cnl field
I'm new to Drupal and I'm looking for a way to add a new field to an already installed content-type in Drupal 7. Please note that some content is already present in the database. Also, I need to do this programmatically and not via a GUI.
Googling, I have already found the following documents, which seem to be related:
https://api.drupal.org/api/drupal/modules!field!field.module/group/field/7
https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_update_N/7
Still, my ideas are a bit confused and a basic example would clarify things.
This snippet should get you started. It was found on the Drupal Stackexchange. I suggest you check there first in the future.
https://drupal.stackexchange.com/questions/8284/programmatically-create-fields-in-drupal-7
$myField_name = "my_new_field_name";
if(!field_info_field($myField_name)) // check if the field already exists.
{
$field = array(
'field_name' => $myField_name,
'type' => 'image',
);
field_create_field($field);
$field_instance = array(
'field_name' => $myField_name,
'entity_type' => 'node',
'bundle' => 'CONTENT_TYPE_NAME',
'label' => t('Select an image'),
'description' => t(''),
'widget' => array(
'type' => 'image_image',
'weight' => 10,
),
'formatter' => array(
'label' => t('label'),
'format' => 'image'
),
'settings' => array(
'file_directory' => 'photos', // save inside "public://photos"
'max_filesize' => '4M',
'preview_image_style' => 'thumbnail',
'title_field' => TRUE,
'alt_field' => FALSE,
)
);
field_create_instance($field_instance);
drupal_set_message("Field created successfully!");
}
You can execute this code countless ways. I am not privy to the requirements of your project so its hard for me to make a recommendation. You could hook this into the update/install functions, or you could build it into a page hook in a module, or you could just bootstrap any new php file in the root directory with this:
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
How can I store a file in a drupal entity? I have a plublic key to associate to an user so I have created an APIuser entity but I don't know what kind of field give to the public key property
function api_user_schema() {
$schema['api_user'] = array(
'description' => 'The base table for api_user.',
'fields' => array(
'id' => array(
'description' => 'The primary identifier for an artwork.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'public_key' => array(
'description' => 'The primary identifier for the public key.',
'type' => ???,
'unsigned' => TRUE,
'not null' => TRUE,
)
'created' => array(
'description' =>
'The Unix timestamp when the api_user was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' =>
'The Unix timestamp when the api_user was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'unique keys' => array(
'id' => array('id')
),
'primary key' => array('id'),
);
return $schema;
}
What you've got there is the definition of a single database table; Drupal offers no layer on top of that for files, so if you want to store a file you'll have to do so manually.
The best example you can take is that of the core user entity. It defines the picture property, which is an ID referencing an entry in the file_managed table (incidentally this is how all permanent file storage is handled by Drupal core by default).
This is the schema definition for that db column (from user_schema()):
'picture' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => "Foreign key: {file_managed}.fid of user's picture.",
)
Which is very similar to what your definition will need to look like.
From there, have a look at the user_account_form() function (which defines the form element for the picture property), and the user_validate_picture() function, which will show you how to perform the file upload, save the file in the file_managed table, and change the submitted value for the picture field to the relevant file ID (so that it automatically gets saved against the entity).
You'll mostly be replicating the code from those two functions so it won't be that tricky.
I've built an application to run on the client side (JavaScript & HTML) which needs to access and updated data on a server. It has a schema which consists of 5 tables. I've defined exactly what they should look like in JSON. I want these to be available as a JSON service served from a Drupal module. I understand how to use drupal_json_output to provide the results. I just can't find a simple way to ensure the database table is created for them and then to add and remove items from it. I'd like to maintain Drupal's independence from the underlying database. I don't need any search functionality, forms functionality etc. I just want to use Drupal's Database Abstraction.
At the moment I've tried the following in my install file:
/**
* Implements hook_schema
*/
function rcsarooms_schema(){
$schema = array();
$schema['rcsarooms'] = array(
'description' => 'Stores the structured information about the rooms and staircases.',
'fields' => array(
'ID' => array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'description' => 'Primary Key: used in the URLs to identify the entity.'
),'Name' => array(
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
'description' => 'The name used for links in the navigation menues.'
),'ParentID' => array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'description' => 'The ID of the parent element or "Root" if this is a root element'
),'Type' => array(
'type' => 'varchar',
'length' => 15,
'not null' => TRUE,
'description' => 'page, staircase, house, room or special'
),'BathroomSharing' => array(
'type' => 'int',
'description' => 'The number of people the bathroom is shared with (0 for unknown)'
),'RentBand' => array(
'type' => 'int',
'description' => 'The ID of the rent band the room is in.'
),'Floor' => array(
'type' => 'int',
'description' => 'The floor number (0 is courtyard level).'
)
),
'primary key' => array('ID')
);
return $schema;
}
And the following in my module file:
/**
* Implements hook_menu
*/
function rcsarooms_menu(){
$items['rcsarooms'] = array(
'page callback' => 'rcsarooms_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
return $items;
}
function rcsarooms_callback(){
drupal_json_output(db_query("SELECT * FROM {rcsarooms}"));
drupal_exit();
return;
}
This gives the following error when I attempt to navigate to rcsarooms:
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.rcsarooms' doesn't exist: SELECT * FROM {rcsarooms}; Array ( ) in rcsarooms_callback()
You're probably looking for hook_schema() which Drupal will use to create your custom tables when you install your module. It goes in the mymodule.install file.
The Schema API will tell you everything you need to know about data types etc.
For adding/removing items from the database use the db_insert(), db_update() and db_merge() functions