From 8800a936089d85413fe9e3da001de701eab7130d Mon Sep 17 00:00:00 2001
From: baverhey
Date: Sun, 14 Dec 2014 21:26:10 +0100
Subject: [PATCH 1/3] the settings page and nessesairy adjustments
---
serial.inc | 2 ++
serial.info | 2 +-
serial.install | 2 ++
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/serial.inc b/serial.inc
index cb3dec2..c792bf8 100644
--- a/serial.inc
+++ b/serial.inc
@@ -165,6 +165,8 @@ function _serial_generate_value($bundle, $field_name, $delete = TRUE) {
->execute();
}
+ // Return the new unique serial value but first devide with the correction factor.
+ $sid= (int)$sid / variable_get('serial_increment', 1);
// Return the new unique serial value.
return $sid;
}
diff --git a/serial.info b/serial.info
index 56dfddd..dae6acd 100644
--- a/serial.info
+++ b/serial.info
@@ -4,7 +4,7 @@ package = Fields
core = 7.x
dependencies[] = field
files[] = serial.module
-
+configure = admin/settings/serial
; Information added by drupal.org packaging script on 2013-10-15
version = "7.x-1.3"
diff --git a/serial.install b/serial.install
index 18e72bf..e3fc558 100644
--- a/serial.install
+++ b/serial.install
@@ -5,6 +5,8 @@
* Install, update and uninstall functions for the Serial module.
*/
+
+
/**
* Implements hook_uninstall().
*/
--
1.9.1
From b026a9ecdabaf1558245bbb6af5917fd28d4e73a Mon Sep 17 00:00:00 2001
From: baverhey
Date: Sun, 14 Dec 2014 21:34:05 +0100
Subject: [PATCH 2/3] forgot the .module file
---
serial.module | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)
diff --git a/serial.module b/serial.module
index 688bb10..dfcf7e0 100644
--- a/serial.module
+++ b/serial.module
@@ -5,6 +5,97 @@
* The Serial module main file.
*/
+
+//==================//
+// Viewable pages //
+//==================//
+
+/**
+ * Implements hook_help().
+ */
+function serial_help($path, $arg) {
+ switch ($path) {
+// Main module help for the serial module
+ case 'admin/help#serial':
+ return '' . t('The serial field relies on the mysql database auto increment value, to provide unique serial fields(asyncronus writing safe)
+ On shared hosting or shared databases the auto_increment_increment is not editable, but lucaly on the settings page it is.
+ The mysql related help page.
+
+ Warning:
+
+ - Use only when you know what your doing!
+ - First number will be 0 when using the correction factor
+ - The used formula is: sid= sid_fromdb / correction_factor
+ eg: when auto incremnt is 7 you put 7 in the field
',
+ array('@mysql_help' => url('https://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html'))) . '
';
+// Help for another path in the block module
+ case 'admin/serial':
+ return '' . t('More help or same help text') . '
';
+ }
+}
+
+
+
+/**
+ * Implements hook_menu().
+ * That calls the settings form
+ */
+function serial_menu() {
+ $items = array();
+ $items['admin/settings/serial'] = array(
+ 'title' => 'Administer serial field',
+ 'description' => t('Settings page for serial field'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('serial_settings_form'),
+ 'access arguments' => array('administer serial settings'),
+ );
+
+ return $items;
+}
+
+
+/**
+ * Form builder.
+ * For the settings form
+ */
+function serial_settings_form($form, &$form_state) {
+ $form['serial_increment'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Increment neutralise factor to use'),
+ '#default_value' => variable_get('serial_increment', 1),
+ '#description' => t("Set the wanted value you want to use neutralize the increment. Can also be used to change the increment value otherwise"),
+ '#required' => TRUE,
+ );
+
+ return system_settings_form($form);
+}
+
+/**
+ * Form validate handler.
+ * The value must be an integer
+ */
+function serial_settings_form_validate($form, &$form_state) {
+
+ $increment = $form_state['values']['serial_increment'];
+ if (!is_numeric($increment)) {
+ form_set_error('serial_increment', t('You must enter an integer for the increment field.'));
+ }
+
+ if (is_numeric($increment) && $increment==0) {
+ form_set_error('serial_increment', t('You must enter an integer other than 0'));
+ }
+
+}
+
+
+
+/**
+ * Form submit handler.
+ */
+function serial__settings_form_submit($form, &$form_state) {
+}
+
+
//==================//
// Field Definition //
//==================//
--
1.9.1
From ec1558fadd60cbe57999b627050508b9f712fe2d Mon Sep 17 00:00:00 2001
From: baverhey
Date: Thu, 18 Dec 2014 22:22:46 +0100
Subject: [PATCH 3/3] drupal coding standards
---
serial.module | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/serial.module b/serial.module
index dfcf7e0..0625f33 100644
--- a/serial.module
+++ b/serial.module
@@ -87,15 +87,6 @@ function serial_settings_form_validate($form, &$form_state) {
}
-
-
-/**
- * Form submit handler.
- */
-function serial__settings_form_submit($form, &$form_state) {
-}
-
-
//==================//
// Field Definition //
//==================//
@@ -322,4 +313,3 @@ function serial_field_widget(&$form, &$form_state, $field, $instance, $items, $d
)
);
}
-
--
1.9.1