Jump to:

5521 Posts in 1733 Topics by 1220 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Changing TextField / Varchar length

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 732 Views
  • Forte
    Avatar
    Community Member
    3 Posts

    Changing TextField / Varchar length Link to this post

    Hello everyone,

    I am not very familiar with SilverStripe but have been asked to do some maintenance on a site using SilverStripe for a client.

    The client's SilverStripe site has a homepage (HomePage.php / HomePage.ss, extends Page), that has a "Main" section, under which there is an editable TextField.

    The problem is, whenever the client goes to add more than 50 characters to this TextField, everything after the 50th character gets truncated. The TextField itself does not have a $maxLength set, so it's possible to actually input more than 50 characters, but when they click "Save" and reload the page, only the first 50 characters remain.

    I believe I've narrowed the problem down to the fact that the "static $db" array entry for this TextField is set to a "Varchar," and as I understand it if no length is specified for the Varchar then it takes a default length of 50 characters.

    My problem is, if I change the $db array entry for this TextField to something else -- for example, "Varchar(200)" or "HTMLText", nothing appears to actually change. I upload the modified HomePage.php file, go into the CMS, and put more than 50 characters into the text field and click save, but it continues to be truncated to 50 characters regardless of what I changed the $db array entry to.

    I suspect that the database itself needs to also be modified, but I have no idea where the data for this TextField would be stored in the database to modify it.

    Does anyone have any ideas as to what I am missing, or which table (if any?) this data is stored in, or where I should look from here? Being unfamiliar with SilverStripe and how it stores data in the database, I am a little stumped. I would appreciate any help or direction you can give!

    Thanks for your time,
    Josh

  • Tim Snadden
    Avatar
    Community Member
    32 Posts

    Re: Changing TextField / Varchar length Link to this post

    You are on the right track. To make the modifications in the database you need to run http://<yoursite>/dev/build

  • Forte
    Avatar
    Community Member
    3 Posts

    Re: Changing TextField / Varchar length Link to this post

    Awesome, thank you, I will give that a shot.

    Before I do though, can you just confirm for me what exactly this will do? Is it building only the internal database table that SilverStripe uses, or is it doing other things as well?

    Also, is there an easy way to back up the current state (before running /dev/build) so that if something breaks I can restore it?

    Once again, thank you very much for your help!

    Happy holidays,
    Josh

  • Tim Snadden
    Avatar
    Community Member
    32 Posts

    Re: Changing TextField / Varchar length Link to this post

    Unless you have an unusual setup all of the database tables will be being used by silverstripe and will have been created by running /dev/build which runs through your code and creates/modifies the database structure accordingly. In this case it will modify the column to have a 200 char limit or whatever you specified in $db.

    What you are aiming to do is a very straightforward change but if you want to back up your db beforehand then there are a number of ways of doing it. Via terminal...

    mysqldump -uYourUsername -pYourPassword yourdbname > yourdbname.sql

    or Doing something similar with any other tool such as phpmyadmin or a desktop app. I'm assuming you are using mysql but it there are similar tools available for any other database.

    I'm also assuming that you aren't doing this directly on your production web server! The truth is that for a minor change like this it's highly unlikely to cause any problems but it's a pretty bad habit to get into. Run this in your local dev environment first and confirm that it's all working as expected before pushing the code to production and running /dev/build. To do this when the server is in 'live' mode you'll need to be logged in.

  • Forte
    Avatar
    Community Member
    3 Posts

    Re: Changing TextField / Varchar length Link to this post

    Thank you Tim!

    This is just a confirmation post that running /dev/build?flush=1 was successful in changing the database and now the TextField is not getting cut off at 50 characters anymore. Thanks again for your quick and articulate responses!

    Unfortunately our company neither designed the site nor runs its servers, and apparently there is indeed only a single production environment on which the CMS is installed; there is no development environment! (Unbelievable, I know.) Hence the question about backing everything up beforehand which also went without a hitch.

    Thank you again, and enjoy your holiday! : )
    Josh

    732 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.